PDA

View Full Version : Saving mixed data in scientific python


Glenn Jones
January 19th, 2009, 05:40 PM
Hi,

So I've recently moved away from using matlab to use scientific python using predominantly pylab, numpy and scipy. I am however having difficultie in saving a mixed data format of the following structure:

# Header 1
# Header 2
x(1) y(1) z(1)
. . .
. . .
. . .
x(N) y(N) z(N)

I can save the header files quite easily using the following:

f=open('myfile.txt','w')
f.write('#Header1\n#Header2)
f.close


When I more myfile.txt I get
#Header1
#Header2


The difficultie I'm having is storing the array below the header. The x,y,z data is stored as a numpy.ndarray called XYZ. I have tried pickling the data but I must admit I'm not sure what I'm doing.

Can any of you guys help? Are there any numpy/scipy modules I can use?

Cheers

sjbaugh
January 19th, 2009, 07:55 PM
Glenn,

I don't know scientific python/Pylab etc but the write statement you have in normal python will only write what you are getting.

You may try:


f=open('myfile.txt','w')
f.write('#Header1\n#Header2)
f.write(XYZ)
f.close

and see if the output is useful to you. Other wise if nobody can find a library routine to help you may have to iterate through the array with for statements and write each element individually.

Hope this helps,

Steve

ssam
January 20th, 2009, 05:59 AM
there are some examples at http://www.scipy.org/Cookbook/InputOutput that may help you.