Python 2.7 堆叠数组并将其放入dat文件
到目前为止,在我的代码中:Python 2.7 堆叠数组并将其放入dat文件,python-2.7,numpy,Python 2.7,Numpy,到目前为止,在我的代码中: a = np.array((1,2,3,4)) b = np.array((11,21,31,41)) np.column_stack((a,b)) array([[1, 11], [2, 21], [3, 31], [4. 41], 我想知道如何设置代码,以便将列写入dat文件?查看np.savetxt: In [9]: np.savetxt('test.dat', c, fmt='%d') In [10]: !ca
a = np.array((1,2,3,4))
b = np.array((11,21,31,41))
np.column_stack((a,b))
array([[1, 11],
[2, 21],
[3, 31],
[4. 41],
我想知道如何设置代码,以便将列写入dat文件?查看
np.savetxt
:
In [9]: np.savetxt('test.dat', c, fmt='%d')
In [10]: !cat test.dat
1 11
2 21
3 31
4 41
您始终可以使用np.savetxt
中的fmt
选项指定格式:
In [9]: np.savetxt('test.dat', c, fmt='%d')
In [10]: !cat test.dat
1 11
2 21
3 31
4 41
“dat”文件是什么意思?是否要将所有值作为连续字节写入二进制文件?是。我只想要一个文本文件中第一列是数组a,第二列是数组b的文件。@user1821176没问题。请注意,如果此解决方案正确并回答了您原来的问题,那么您应该接受此解决方案。