[Numpy-discussion] Creating multirow numpy rec.arrays

Francesc Altet faltet at carabos.com
Wed Jan 25 04:16:02 CST 2006


This exposes a weird behaviour when building heterogeneous arrays in

In [85]: xcol = numpy.ones((3,2), 'int32')

In [86]: numpy.array([(xcol[0],)], dtype=[('x','i4', (2,))])
Out[86]: array([(array([1, 1]),)], dtype=(void,8))

So far so good. Now:

In [89]: numpy.array([xcol], dtype=[('x','i4', (2,))])
<ERROR: expected a readable buffer object>
array([[[(array([-1208633192, -1208633192]),), (array([15, 15]),)],
        [(array([  0, 185]),), (array([         18, -1208633016]),)],
        [(array([480,  21]),), (array([21, 21]),)]]], dtype=(void,8))

While I'd expect:

In [89]: numpy.array([xcol], dtype=[('x','i4', (2,))])
Out[89]: array([(array([1, 1]),
                (array([1, 1]),
		(array([1, 1]))], dtype=(void,8))

Also, for the whishlist: It would be nice if one can specify the shape
of the array to be built in the factory itself. I mean, allowing
something like:

In [90]: numpy.array([xcol], dtype=[('x','i4', (2,))], shape=2)
Out[90]: array([(array([1, 1]),
		(array([1, 1]))], dtype=(void,8))


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

More information about the Numpy-discussion mailing list