[Tutor] Re: Fastest way to write/read numerical data into/from
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 :).
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.
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