[英]how to save a 2d numpy array into a text file
I have this following code where "final" is an array [ 2. 75.75 73.875 93.625 7. 29.369]我有以下代码,其中“final”是一个数组 [2.75.75 73.875 93.625 7.29.369]
now, how do I save the reshaped 2d matrix "fin" as a .txt file.现在,如何将重塑后的二维矩阵“fin”保存为 .txt 文件。
and if it is saved as a text file, how do I get back the same as a matrix in a different program, where I open the text file如果它被保存为文本文件,我如何在不同的程序中恢复与矩阵相同的内容,在那里我打开文本文件
fin = numpy.reshape(final,(-1,3))
print(fin)
print(fin[0][2])
output of above code上面代码的输出
[[ 2. 75.75 73.875]
[93.625 7. 29.369]]
73.875
To save the file : you can use : np.savetxt("file.csv", final, delimiter=",")
.here's the documentation if you want to modify more parameters要保存文件:您可以使用:
np.savetxt("file.csv", final, delimiter=",")
如果您想修改更多参数,请参阅文档
To open it in another file : new_array = np.genfromtxt("file.csv", delimiter=",")
.here's the documentation要在另一个文件中打开它:
new_array = np.genfromtxt("file.csv", delimiter=",")
这是文档
您可以尝试以下方法:)
np.savetxt("final.csv", final, delimiter=",")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.