[Numpy-discussion] Conversion of heterogeneous arrays in numpy<-->numarray

Francesc Altet faltet at carabos.com
Tue Jan 10 10:59:13 CST 2006


Hi,

Is there any plan to provide a conversion between recarrays in numpy
and numarray?. For the moment it does not seem to work:

In [83]: r=numarray.records.array([(1,11,'a'),(2,22,'b')], formats='u1,f4,a1')

In [84]: a=numpy.array(r, dtype='u1,f4,a1')

In [85]: numarray.records.array(a)
---------------------------------------------------------------------------
exceptions.ValueError                                Traceback (most recent 
call last)

/tmp/<console>

/usr/lib/python2.3/site-packages/numarray-1.5.0-py2.3-linux-i686.egg/numarray/records.py 
in array(buffer, formats, shape, names, byteorder, aligned)
    406                     byteorder=byteorder, aligned=aligned)
    407     else:
--> 408         raise ValueError("Unknown input type")
    409
    410 def _RecGetType(name):

ValueError: Unknown input type

In [86]: numpy.array(r)
Out[86]: array([0Aa, °Ab], dtype=(void,6))

However, if one specifies the format in for the numarray-->numpy it
does seem to work:

In [87]: numpy.array(r, dtype='u1,f4,a1')
Out[87]: array([(1, 11.0, 'a'), (2, 22.0, 'b')], dtype=(void,6))

But not in the sense numpy-->numarray:

In [88]: numarray.records.array(a, formats='u1,f4,a1')
---------------------------------------------------------------------------
exceptions.ValueError                                Traceback (most recent 
call last)

/tmp/<console>

/usr/lib/python2.3/site-packages/numarray-1.5.0-py2.3-linux-i686.egg/numarray/records.py 
in array(buffer, formats, shape, names, byteorder, aligned)
    406                     byteorder=byteorder, aligned=aligned)
    407     else:
--> 408         raise ValueError("Unknown input type")
    409
    410 def _RecGetType(name):

ValueError: Unknown input type

Having this would be great for supporting heterogeneous arrays in
PyTables.

Regards,

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"





More information about the Numpy-discussion mailing list