[SciPy-user] Multicolumn file io

Stéfan van der Walt stefan@sun.ac...
Sat Feb 14 15:44:55 CST 2009


2009/2/15 Mani chandra <mchandra@iitk.ac.in>:
>    How can I can output my data in 1D arrays to a file as seperate
> columns? For ex, my data is like x = numpy.mgrid[0:10:10j], y =
> numpy.mgrid[0:10:10j], or x = numpy.arange(0, 10, 1), y =
> numpy.arange(0, 10, 1), and I'd like the data outputted to a file like :
> #x    y
> 0      0
> 1       1
> 2       2
>
>          and so on...

np.savetxt('/tmp/data.txt', np.array([x, y]).T)

or

np.savetxt('/tmp/data.txt', np.array([x, y]).T, fmt='%.0f')

Stéfan


More information about the SciPy-user mailing list