[Numpy-discussion] Conversion numarray/Numeric objects

Todd Miller jmiller at stsci.edu
Thu Sep 19 09:49:02 CDT 2002

Aureli Soria Frisch wrote:

> Hi,
> I have developed till now all my numerical stuff using Numeric objects.
> I want to use some modules using numarray. I have tested some 
> conversion functions on Python, e.g.
> numarray.array(Numeric_object.tolist())
Much faster,  but less general, is:

numarray.fromstring(Numeric_object.tostring(), type=XXXX)

> but it seems to me a bit slow (specially for large arrays as images). 
> Is there any more ways of doing this conversion?
> Should I write my own conversion in C?
It depends on how soon you need it to be fast.    numarray 
fromlist/tolist should be implemented in C for the next release, which 
should occur within a couple months, perhaps sooner.  If you want to 
write a C extension for numarray now, the best way to do it is to use 
the Numeric compatability layer,   which essentially uses a subset of 
the Numeric C-API,  and is not likely to change.

> Which advices could you give me in order to make an smoother transition?
> Furthermore I found the web site about numarray/Numeric 
> incompatibilities very interesting. However I did not understand quite 
> well the paragraph:
I think that webpage is out of date.

> since interactively typing a.shape() or a.shape((8,8)) raise an 
> exception (Tuple object not callable). Am I misunderstanding something?
Actually, for python 2.2 and up,  numarray has all of those attributes 
in a Numeric compatible, Python properties based form.   So ".shape" 
get/sets the shape in numarray, just as in Numeric:

 >>> import numarray
 >>> a = numarray.arange(10)
 >>> a.shape
 >>> a.shape = (2,5)
 >>> a.shape

Because of this,  the expression a.shape() that you mentioned tries to 
"call" the shape tuple returned by .shape, resulting in an exception.


Todd Miller 			jmiller at stsci.edu

More information about the Numpy-discussion mailing list