[英]AttributeError: 'numpy.ndarray' object has no attribute 'append' error
Hello Guys I am new to Machine and Trying to learn it from you-tube but when i run their code on my computer i got this error Please help....!!!!大家好,我是机器的新手,并试图从你的电子管中学习它,但是当我在我的计算机上运行他们的代码时,我得到了这个错误请帮助....!!!!
Code:代码:
import random
random.shuffle(training_data)
for sample in training_data:
print(sample[1])
X = []
y = []
y = np.array(y)
for features , label in training_data:
X.append(features)
y.append(label)
X = np.array(X).reshape(-1 , IMG_SIZE , IMG_SIZE,1)
Move your y to numpy to after loop.将您的 y 移动到 numpy 到循环后。 As @Tyberius mentioned in the comments, you cannot append to numpy array.正如评论中提到的@Tyberius,您不能将 append 转换为 numpy 数组。 Therefore, you need to keep y
as list in your for loop and then convert it after appending.因此,您需要将y
保留为 for 循环中的列表,然后在附加后对其进行转换。 Like here:像这儿:
import random
random.shuffle(training_data)
for sample in training_data:
print(sample[1])
X = []
y = []
for features , label in training_data:
X.append(features)
y.append(label)
y = np.array(y)
X = np.array(X).reshape(-1 , IMG_SIZE , IMG_SIZE,1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.