2

到目前为止,在我的代码中:

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 文件?

4

1 回答 1

2

看看np.savetxt

http://docs.scipy.org/doc/numpy/reference/generated/numpy.savetxt.html

In [2]: a = np.array((1,2,3,4))

In [3]: b = np.array((11,21,31,41))

In [5]: c = np.column_stack((a,b))

In [7]: np.savetxt('test.dat', c)

In [8]: !cat test.dat
1.000000000000000000e+00 1.100000000000000000e+01
2.000000000000000000e+00 2.100000000000000000e+01
3.000000000000000000e+00 3.100000000000000000e+01
4.000000000000000000e+00 4.100000000000000000e+01

您始终可以使用以下fmt选项指定格式np.savetxt

In [9]: np.savetxt('test.dat', c, fmt='%d')

In [10]: !cat test.dat
1 11
2 21
3 31
4 41
于 2013-06-09T22:02:12.217 回答