Numeric.tostring() ?

Robert Thomas Kern kernr at mail.ncifcrf.gov
Mon May 10 20:38:22 EDT 1999


On Mon, 10 May 1999 17:50:28 -0400, "Tom Lukasiak"
<Tomasz_Lukasiak at Brown.EDU> wrote:

>Hi,
>    I have found that the best way (or maybe the only way) to read a binary
>image into an array is to do something like this:
>
>f = open(filename)
>data = f.read()
>f.close()
>dataArray = Numeric.fromstring(data, Numeric.Int16)
>
>
>However, I run into trouble when I want to convert a Numeric array into a
>data string, so that I could save my array as a binary image file.  This is
>because there is no Numeric.tostring() method.  What is the best way to fix
>this problem?

tostring() is not a function in the Numeric module.  Rather, it is a
method of NumPy arrays.  Use dataArray.tostring().

>Thanks for any help.

Any time.

BTW, if you are reading from a file instead of from a PIL Image
instance, you can try Travis Oliphant's NumpyIO extension module.  It
allows you to read a file straight into a NumPy array rather than
going through a string intermediate.  Saves on memory.  It is part of
his signaltools package although it can be compiled separately.
(http://oliphant.netpedia.net/packages/signaltools-0.5.tgz)  A Linux
RPM is also available at the root page.

>Tom





More information about the Python-list mailing list