[SciPy-user] Saving Data as Modul!!

Steve Schmerler elcorto at gmx.net
Mon Nov 6 12:41:10 CST 2006


Johannes Loehnert wrote:

> 
> How do you deal with large arrays? Do you store them as ASCII data or as 
> binary string? If second, how?
> 

I do it like this:

write:
f = open(filename, "wb")
_data = numpy.asarray(data, dtype)
if sys.byteorder == 'big':
	_data = _data.byteswap()
f.write(_data)
f.close()


read:
f = open(filename, "rb")
data = f.read()
f.close()
_data = numpy.fromstring(data, dtype)
if sys.byteorder == 'big':
	_data = _data.byteswap()

_data: numpy array
usually dtype = 'd'

This reads and writes always in little endian (I do this because I 
interchange data from several machines).

HTH

-- 
cheers,
steve

Random number generation is the art of producing pure gibberish as 
quickly as possible.


More information about the SciPy-user mailing list