简体   繁体   English

AttributeError: 'numpy.ndarray' object 没有属性 'append' 错误

[英]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)

enter image description here在此处输入图像描述

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.

相关问题 AttributeError: 'numpy.ndarray' 对象没有属性 'append' - AttributeError: 'numpy.ndarray' object has no attribute 'append' Python - AttributeError:'numpy.ndarray'对象没有属性'append' - Python - AttributeError: 'numpy.ndarray' object has no attribute 'append' AttributeError:“ numpy.ndarray”对象没有属性“ A” - AttributeError: 'numpy.ndarray' object has no attribute 'A' 为什么 python 抛出错误:AttributeError: 'numpy.ndarray' object has no attribute 'append'? - Why is python throwing error : AttributeError: 'numpy.ndarray' object has no attribute 'append'? AttributeError: 'numpy.ndarray' object has no attribute 'score' 错误 - AttributeError: 'numpy.ndarray' object has no attribute 'score' error numpy.ndarray' object 没有属性 'append - numpy.ndarray' object has no attribute 'append 'numpy.ndarray' 对象没有属性 'append' - 'numpy.ndarray' object has no attribute 'append' 如何修复此错误:numpy.ndarray“对象没有属性” append” - how to fix this error : numpy.ndarray “ object has no attribute ”append" Numpy和Matplotlib-AttributeError:“ numpy.ndarray”对象没有属性“ replace” - Numpy and Matplotlib - AttributeError: 'numpy.ndarray' object has no attribute 'replace' AttributeError:'numpy.ndarray'对象没有属性'append':图像处理示例 - AttributeError: 'numpy.ndarray' object has no attribute 'append':Image processing example
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM