我有一个在每次迭代中生成一维 numpy 数组的代码。我希望将数组附加到 CSV 文件的末尾,以便我可以从 Excel 中读取所有数据。我目前正在尝试以下方法:
for loop in range(0,10):
# The following part generates the array
Array1 = numpy.array([4.3])
Array2 = numpy.array([10.2])
Array3 = numpy.concatenate((Array1,Array2),axis=0)
# The following part tries to generate a CSV writable array. But it fails :S
if (loop == 0):
ArrayMain = Array3
else:
# Trying to append the new array with the previous array
ArrayMain = numpy.asarray(ArrayMain,Array3)
# Trying to write the array into a .txt. file in .csv format
numpy.savetxt("ArrayMain.csv", ArrayMain, delimiter=",",fmt='%.3f')
此代码给出错误。知道如何纠正它吗?