From: Randy H. <he...@in...> - 2004-04-08 17:38:49
|
What's the easiest way to write a Numeric array to a file? Thanks! --Randy |
From: John H. <jdh...@ac...> - 2004-04-08 18:41:35
|
>>>>> "Randy" == Randy Heiland <he...@in...> writes: Randy> What's the easiest way to write a Numeric array to a file? Easiest or best? In the next release I've added load and save funcs for converting arrays to and from ascii files. But this is slow and generally lossy. Best is to use the binary string operations tostring and fromstring from Numeric import fromstring, Float # write file('fname.out', 'wb').write(x.tostring()) # read x = fromstring(file('fname.out', 'rb').read(), Float) #If data is MxN you'll need to reshape x.shape = M,N Hope this help, JDH |
From: Perry G. <pe...@st...> - 2004-04-08 18:47:53
|
John Hunter wrote: > Best is to use the binary string operations tostring and fromstring > > from Numeric import fromstring, Float > # write > file('fname.out', 'wb').write(x.tostring()) > > # read > x = fromstring(file('fname.out', 'rb').read(), Float) > > #If data is MxN you'll need to reshape > x.shape = M,N > > Hope this help, > JDH > Note that numarray has a tofile method and a fromfile function to do this without going through the copying required by tostring and fromstring. Like those, it also doesn't save any shape or type info in the file. Perry |
From: Randy H. <he...@in...> - 2004-04-08 19:04:59
|
Thanks much John & Perry! Part of my confusion was the fact that I'm using numarray on my laptop/Windows and Numeric on Linux... and I was in a hurry... and general ignorance. Anyway, thanks again. Randy > -----Original Message----- > From: Perry Greenfield [mailto:pe...@st...] > Sent: Thursday, April 08, 2004 1:48 PM > To: John Hunter; Randy Heiland > Cc: mat...@li... > Subject: RE: [Matplotlib-users] writing binary array to file > > John Hunter wrote: > > Best is to use the binary string operations tostring and fromstring > > > > from Numeric import fromstring, Float > > # write > > file('fname.out', 'wb').write(x.tostring()) > > > > # read > > x = fromstring(file('fname.out', 'rb').read(), Float) > > > > #If data is MxN you'll need to reshape > > x.shape = M,N > > > > Hope this help, > > JDH > > > > Note that numarray has a tofile method and a fromfile function > to do this without going through the copying required by tostring > and fromstring. Like those, it also doesn't save any shape or > type info in the file. > > Perry > |
From: Eugeni D. <dol...@rs...> - 2004-04-09 08:25:36
|
----- Original Message ----- From: "Perry Greenfield" <pe...@st...> To: "John Hunter" <jdh...@ni...>; "Randy Heiland" <he...@in...> Cc: <mat...@li...> Sent: Thursday, April 08, 2004 10:47 PM Subject: RE: [Matplotlib-users] writing binary array to file > John Hunter wrote: > > Best is to use the binary string operations tostring and fromstring > > > > from Numeric import fromstring, Float > > # write > > file('fname.out', 'wb').write(x.tostring()) > > > > # read > > x = fromstring(file('fname.out', 'rb').read(), Float) > > > > #If data is MxN you'll need to reshape > > x.shape = M,N > > > > Hope this help, > > JDH > > > > Note that numarray has a tofile method and a fromfile function > to do this without going through the copying required by tostring > and fromstring. Like those, it also doesn't save any shape or Moreover tostring() and fromstring() are deprecated iirc, because you can convert arrays from and to strings by StringIO. > type info in the file. > > Perry > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: Perry G. <pe...@st...> - 2004-04-14 19:10:19
|
Eugeni Doljenko writes: > > John Hunter wrote: > > > Best is to use the binary string operations tostring and fromstring > > > > > > from Numeric import fromstring, Float > > > # write > > > file('fname.out', 'wb').write(x.tostring()) > > > > > > # read > > > x = fromstring(file('fname.out', 'rb').read(), Float) > > > > > > #If data is MxN you'll need to reshape > > > x.shape = M,N > > > > > > Hope this help, > > > JDH > > > > > > > Note that numarray has a tofile method and a fromfile function > > to do this without going through the copying required by tostring > > and fromstring. Like those, it also doesn't save any shape or > Moreover tostring() and fromstring() are deprecated iirc, because you can > convert arrays from and to strings by StringIO. > I just noticed this recently. It isn't the case that tostring and fromstring are deprecated for numarray. I just wanted to clarify. Perry |
From: Flavio C. C. <fcc...@ci...> - 2004-04-12 16:04:36
|
If you're not intereste in creating a text file, The best way to go, is with pickle.dump and pickle.load Check the python docs about them. cheers, Fl=E1vio On Thu, 2004-04-08 at 17:38, Randy Heiland wrote: > What's the easiest way to write a Numeric array to a file? > Thanks! --Randy >=20 >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli= ck > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |