【问题标题】:IndexError: index 1 is out of bounds for axis 0 with size 1 // PythonIndexError: index 1 is out of bounds for axis 0 with size 1 // Python
【发布时间】:2017-04-09 17:58:43
【问题描述】:

我收到此代码的错误消息:

    def capture_and_decode(self, bitrange = 2, axes = [1]):

    cam_width, cam_height = self.camera.resolution
    #cam_width = 640
    #cam_height = 480
    print ('a')
    scr_range = self.display.displaywindow.resolution
    self.raw_images = numpy.empty((len(axes), cam_height, cam_width, bitrange))
    imgs = []
    for axis in axes:

       for bits in range(0, bitrange):
           stripe_width = cam_width // 2 ** (bits + 1)
           #print(stripe_width)
           binary = numpy.fromiter(GrayCode(bits + 1).generate_gray(), dtype=numpy.int) % 2
           vector = numpy.repeat(binary, stripe_width)
           imgs = numpy.tile(vector, (cam_height, 1))
           print ('b')
       self.display.displaywindow.show(imgs)  # TODO: handle sleep in display module
       time.sleep(0.25)
       self.raw_images[axis, :, :,  bitrange] = self.camera.capture()

    imgs_v = self.raw_images[0].reshape(cam_height, cam_width, -1)
    print('c')
    imgs_h = self.raw_images[1].reshape(cam_height, cam_width, -1)
    print('C')


    self.registration, self.modulation = decode(imgs_v, imgs_h, bitrange)
    print('d')
    self.sigCaptureDone.emit(self.registration)

    with h5py.File("test.h5", "w") as f:
        f.create_dataset("registration", data=self.registration)
        print('e')
        f.create_dataset("modulation", data=self.modulation)
        print('finish')

文件“....../GrayCodeWidget.py”,第 89 行,在 capture_and_decode self.raw_images[轴,:, :, bitrange] = self.camera.capture() IndexError:索引 1 超出轴 0 的范围,大小为 1

【问题讨论】:

    标签: python python-3.x index-error


    【解决方案1】:

    我不熟悉 Python,但通常索引应该以 0 开头。

    使用是否合法: def capture_and_decode(self, bitrange = 2, axes = [0]): ?

    【讨论】:

    • 你能得到self.raw_images[axis, :, :, bitrange]的转储吗?
    猜你喜欢
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 2019-09-21
    • 1970-01-01
    • 2020-03-13
    • 2020-05-22
    • 2017-05-20
    • 1970-01-01
    相关资源
    最近更新 更多