From: kernr at mail.ncifcrf.gov (Robert Thomas Kern)
Date: Tue, 11 May 1999 00:38:22 GMT
Subject: Numeric.tostring() ?
References: <7h7k9h$dme@cocoa.brown.edu>
Message-ID: <37377a46.10698636@news.erols.com>
Content-Length: 1183
X-UID: 1846                                                 

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





