Converting a list to a Numarray array?

Alex Martelli aleax at aleax.it
Mon Feb 24 13:02:19 EST 2003


S Timmins wrote:

> How do I convert a list (read from a file) into a Numarray array so I
> can start using all of the neat Numarray methods (such as reshape)??

Just convert it:

somelist = range(8)  # or whatever
import numarray
anarray = numarray.array(somelist)

that's all -- there's no reshape *method*, but, there IS a reshape
*function* in module numarray, so, e.g.:

>>> numarray.reshape(anarray, (4,2))
array([[0, 1],
       [2, 3],
       [4, 5],
       [6, 7]])
>>>


As a curiosity -- why's a new programmer using the cutting-edge
numarray rather than the tried-and-true Numeric...?  Wouldn't you
rather use a staid, solid package, being a newbie and all...?


Alex





More information about the Python-list mailing list