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

Thomas Nauss nauss at lcrs.de
Sun Dec 3 08:51:25 CST 2006


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)

As you all know better than myself, this results in something like:
1.0000000e+000 2.2720000e-001
9.9999000e-001 2.2910000e-001
9.9998000e-001 2.2970000e-001

But for my purpose, the ASCII file should look like:
SSA            Reflection
1.0000000e+000 2.2720000e-001
9.9999000e-001 2.2910000e-001
9.9998000e-001 2.2970000e-001
with e. g. "SSA" and "Reflection" as column headings.

Thank you in advance for your comments,
Thomas


More information about the SciPy-user mailing list