我正在尝试使用for
循环填充数组,但结果似乎总是最后输入的数字
import numpy as np
quantity = int (input ("enter amount of data"))
for i in range (quantity):
value = float (input ("enter value of x >>"))
x = np.array ([value])
print (x)
答案 0 :(得分:1)
您需要声明数组一次:
quantity = int(input("enter amount of data"))
arr = np.zeros(quantity, dtype=float)
然后根据需要填写单个元素:
for i in range(quantity):
arr[i] = float(input("enter value of x >>"))