内置方法numpy.ndarray对象的散列...数组的插入

时间:2018-09-22 17:03:04

标签: python arrays numpy matrix pretty-print

我想将一些图像转换为numpy数组,并漂亮地打印它们。我已将所有图像存储在numpy数组的数组中。

path = "greyset/"
vector_classwise = [[0 for i in range(200)] for j in range(10)]

for image_path in os.listdir(path):
    inpath = os.path.join(path, image_path)
    img = Image.open(inpath)
    arr = np.array(img)
    shape = arr.shape
    flat_arr = arr.ravel
    vector = np.matrix(flat_arr)

    #image_path is of the form classname_image_number

    class_num = int(image_path[0:3])
    entry = int(image_path[4:7])

    vector_classwise[class_num][entry] = vector

print (vector_classwise[3][5])

但是,当我尝试打印最后一行时,我得到了

[[<built-in method ravel of numpy.ndarray object at 0x7ff472a84490>]]

代替数组。

我试图写这篇文章:

print (vector_classwise[3][5]())

作为建议的答案之一调用该方法,但出现此错误:

TypeError: 'matrix' object is not callable

如何打印出vector_classwise数组中的向量?

0 个答案:

没有答案