[Numpy-discussion] Converting string to array

Andrew Nesbit alnesbit at students.cs.mu.OZ.AU
Mon May 12 23:26:03 CDT 2003


On Tue, 13 May 2003, eric jones wrote:

> Try fromstring.  I think it should do what you want:
> 
> >>> from Numeric import * print fromstring.__doc__
>
> fromstring(string, typecode='l', count=-1) returns a new 1d array
> initialized from the raw binary data in string.  If count is
> positive, the new array will have count elements, otherwise it's
> size is determined by the size of string.

Thanks, Eric.  That did the trick.

The manual said that Numeric.array() takes a sequence type as one of
its arguments, and considering that a string is a sequence type, I
thought that, given an appropriate typecode, it would do the
conversion automatically in the same way that array.array does.  Is
this difference an intended feature of numpy?

Andrew.






More information about the Numpy-discussion mailing list