numpy 有人知道python tensorflow中的这个错误吗?

pbwdgjma  于 2022-11-24  发布在  Python
关注(0)|答案(2)|浏览(217)

这是我的代码:

image_array.append(image)
label_array.append(i)
    
image_array = np.array(image_array)
label_array = np.array(label_array, dtype="float")

这是错误:

AttributeError: 'numpy.ndarray' object has no attribute 'append'
8xiog9wr

8xiog9wr1#

numpy.append至少需要两个输入。请参见以下示例

import numpy as np

#define NumPy array
x = np.array([1, 4, 4, 6, 7, 12, 13, 16, 19, 22, 23])

#append the value '25' to end of NumPy array
x = np.append(x, 25)

#view updated array
x

array([ 1,  4,  4,  6,  7, 12, 13, 16, 19, 22, 23, 25])
kqlmhetl

kqlmhetl2#

据我所知,您编写append的方式是错误的(请查看文档https://numpy.org/doc/stable/reference/generated/numpy.append.html中的示例)

image_array = np.append(image_array, [image])
label_array = np.append(label_array, [i])

数组必须具有相同的维度

相关问题