[SciPy-user] Saving data as a Modul!!

Volker Lorrmann lorrmann at physik.uni-wuerzburg.de
Tue Nov 7 04:12:15 EST 2006


Hi guys,

thanks for your answers first.
Some data´s i wanna save are 3-dim arrays (size:6,600,1000), others are 
objects.
I found "save" from scipy.io, which is exactly what i´m looking for.

Here´s what i´m doing (Here the object is just named as "object", the 
array, "array") ;) ):

 >>> save('my_object', {'object': object})     # saves the object into 
the modul "my_data.py"
 >>> save('my_array', {'array': array})
 >>> from my_object import *                           
 >>> from my_array import *                        # and all my data´s 
are back

Maybe this will be usefull for others too.

Greetings

Volker




>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 6 Nov 2006 19:17:30 +0100
> From: Johannes Loehnert <a.u.r.e.l.i.a.n at gmx.net>
> Subject: Re: [SciPy-user] Saving Data as Modul!!
> To: SciPy Users List <scipy-user at scipy.org>
> Message-ID: <200611061917.31354.a.u.r.e.l.i.a.n at gmx.net>
> Content-Type: text/plain;  charset="iso-8859-1"
>
> Hi,
>
>   
>> Actually I've done what Volker asks in several different ways, although
>> none of the solutions is general enough to post here. The most fun
>> instance was saving electrophysiology recordings to a .py file such that
>> I could double-click the file and have the __main__ function plot the
>> data! In fact, now that I think about it, I've constructed most of my
>> examples to operate in this way -- run the .py file as a script and see
>> the data it contains in some kind of visualization. "import" it and use
>> it in another module. The nice thing about making it a module is that it
>> goes along for the ride with distutils without you having to even think
>> about it.
>>     
>
> Actually I had similar thoughts recently. However I did not think about 
> storing everything into a .py file, I was more along the line of storing a 
> chunk of plotting code with the data.
>
> How do you deal with large arrays? Do you store them as ASCII data or as 
> binary string? If second, how?
>
> Johannes
>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 06 Nov 2006 19:41:10 +0100
> From: Steve Schmerler <elcorto at gmx.net>
> Subject: Re: [SciPy-user] Saving Data as Modul!!
> To: SciPy Users List <scipy-user at scipy.org>
> Message-ID: <454F81C6.10209 at gmx.net>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> 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
>
>   


-- 
-----------------------
Volker Lorrmann
Universität Würzburg
Experimentelle Physik 6
Am Hubland
97074 Wuerzburg
Germany
Tel: +49 931 888 5770
volker.lorrmann at physik.uni-wuerzburg.de





More information about the SciPy-User mailing list