Saving (and loading) binary data with matrix shape and type storage

Hi,

How can I save (and relaod) a matrix into a binary file *with* matrix shape and type storage.
I have a feature request :
Basically, it would be great to be able to do something like :

X = rand(100,100)
BSave('foo.dat', X)
Y = BLoad('foo.dat')

and at this point, we sould have X==Y (without having to use reshape and having to take care on types)

Waiting for such a feature, I'm using gzipped ASCII files but IMHO it is far to be the best solution.

Cheers.
Xavier.
ps : Everything else seems to work just great in 0.72 : Thank's for all the job on matplotlib.

Xavier Gnata wrote:

Hi,

How can I save (and relaod) a matrix into a binary file *with* matrix shape and type storage.
I have a feature request :
Basically, it would be great to be able to do something like :

X = rand(100,100)
BSave('foo.dat', X)
Y = BLoad('foo.dat')

I don't know of an existing function that does this, but it would not be hard to roll your own. All you need to do is first write the dimensions and type of the array to the file, then the binary data. To read it back in, you'd first read in the meta data, then the binary data, and you're done.

I've enclosed a quickie prototype (using Numeric, I think numarray may have tofile() and fromfile() methods, and it handles typecode differently.

By the way, there may be something in SciPy for this, and it's also possible that arrays can be pickled.

This is also a better question for the NumPy list than this list.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

OOPS, forgot the enclosure.

-Chris

BinaryArraySaver.py (1.93 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...