[Tutor] Re: Fastest way to write/read numerical data into/from a file?

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Jun 30 14:29:42 EDT 2004



On Wed, 30 Jun 2004, Andrei wrote:

> Karthikesh Raju wrote on Wed, 30 Jun 2004 19:16:40 +0300:
>
> > i have written a module that saves matrices in a file. Basically, a
> > matrix as
> > A = numarray.array([1,2]) will be saved as 1 2 in the file, and
> > A = numarray.array([[1,2],[3,4]]) as
> > 1 2
> > 3 4
>
> I've never used numarray, so I'll just assume there's no built-in method
> which does this for you :).


According to:

    http://stsdas.stsci.edu/numarray/numarray-0.9.html/node34.html

and:

    http://stsdas.stsci.edu/numarray/numarray-0.9.html/node33.html

there is a built-in method called 'tofile()' that does this for us.
There's a corresponding 'fromfile()' function in the numarray package that
goes the other way.

See:

    http://www.stsci.edu/resources/software_hardware/numarray/userguide

and look for the header "tofile and fromfile capability": there's an
example of how to save numarray arrays to disk.


Caveat: the files that tofile() generates are, unfortunately, platform
specific, so if you need to ensure that the files can be read from any
computer, we can't use the built-in file stuff.



Hope this helps!




More information about the Tutor mailing list