【发布时间】:2020-12-08 04:22:46
【问题描述】:
import numpy as np
Student1= [1,2]
test11= np.array([])
np.clip(0,1,20)
NOF=int(2)
print("Enter test score, students name are (1,2,3, etc): ")
for i in range(NOF):
data=int(input())
test11.append(data)
total=0
for value in test11:
total=total+value
print("The sum of all", total)
列表版本
import numpy as np
Student1= [1,2]
test11= []
NOF=int(2)
print("Enter test score, students name are (1,2,3, etc): ")
for i in range(NOF):
data=int(input())
test11.append(data)
total=0
for value in test11:
total=total+value
print("The sum of all", total)
这会一直报错“numpy.ndarray”对象没有“附加”属性。我希望能够将用户数据添加到数组 test11。无需使 test11 成为 numpy 数组即可正常工作。但我希望能够将数字的大小限制为 20。有什么想法吗?请让它变得简单。
错误代码: 回溯(最近一次通话最后): 第 10 行,在 test11.append(数据) AttributeError: 'numpy.ndarray' 对象没有属性 'append'
【问题讨论】:
-
numpy.ndarray对象确实没有append方法。为什么不使用list? -
请提供完整的错误输出,以及minimal reproducible example。
-
np.clip行对您没有任何作用。重新阅读它的文档。