尝试将对象存储在numpy 2D数组中时出错 - Python

时间:2016-10-12 11:31:59

标签: python arrays object numpy

我有以下代码:

import numpy as np
from scipy import misc
import B as b

class A():
    def __init__(self):
        self.__array = np.empty((4,4), dtype=object)

    def __create_subimages(self):
        i = 0
        j = 0
        k = 0
        l = 0
        position = 0

        while i != self.__rows_quotient * self.__rows:
            sub_image = b.B(self.__image[i:i + self.__rows_quotient, j:j + self.__cols_quotient], position)
            np.append(self.__array, sub_image)
            if j == self.__cols_quotient * (self.__cols - 1):
                j = 0
                i += self.__rows_quotient
            else:
                j += self.__cols_quotient
            if l == len(self.__subimages[0]) - 1:
                l = 0
                k += 1
            else:
                l += 1

            position += 1
            misc.imshow(self.__subimages[0][0].get_image())

另一个班级:

class B():

        def __init__(self, image, position):
            self.__image = image
            self.__position = position

        def get_image(self):
            return self.__image

所以我尝试将对象B存储到numpy数组__subimages,然后在get_image中显示我带有B的内容的图像} class

但是,我收到以下错误输出:

misc.imshow(self.__subimages[0][0].get_image())
AttributeError: 'NoneType' object has no attribute 'get_image'

为什么是Nontype?它应该是一个B对象,它有一个返回数组的方法。

请帮助:(

0 个答案:

没有答案