[SciPy-user] Writing a Numpy array to an ascii file with column headings

Christian Kristukat ckkart at hoc.net
Sun Dec 3 09:09:15 CST 2006


Thomas Nauss wrote:
> Hi there,
> I am a really newby to Python but I hope this is the right place to get 
> an answer for my question: I want to write data from an n-D array to an 
> ASCII file but with column headings.
> 
> I have no problem to store array data in an ASCII file using e. g.:
> from numpy import *
> from scipy.io import write_array
> data = column_stack((array_1D_1,array_1D_2))
> write_array("test.txt", data, separator=' ', linesep='\n', precision=7)

Instead of the filename you may put an open file object. So you can open a file
for writing, write a header and then let io.write_array write the array data.

Christian



More information about the SciPy-user mailing list