[Numpy-tickets] [NumPy] #318: Easy way to increment the nesting level in recarrays

NumPy numpy-tickets at scipy.net
Thu Oct 5 05:27:14 CDT 2006

#318: Easy way to increment the nesting level in recarrays
 Reporter:  faltet       |       Owner:  somebody
     Type:  enhancement  |      Status:  new     
 Priority:  normal       |   Milestone:          
Component:  numpy.core   |     Version:          
 Severity:  normal       |    Keywords:          

 I'd like to see an easy way to increment the level of nesting in
 recarrays. For me, a good way would be that the next could work:

 In [33]:nr=numpy.rec.array("a"*8, dtype=[('x', 'i4'),('y','i4')])
 In [34]:nr
 recarray([(1633771873, 1633771873)],
       dtype=[('x', '<i4'), ('y', '<i4')])
 In [35]:numpy.rec.array(nr, dtype=[('x', 'i4'),('y','i4')])
 recarray([(1633771873, 1633771873)],
       dtype=[('x', '<i4'), ('y', '<i4')])
 # Fine until here, but:
 In [36]:numpy.rec.array(nr, dtype=[('new',[('x', 'i4'),('y','i4')])])
 exceptions.ValueError                                Traceback (most
 recent call last)

 /home/faltet/python.nobackup/numpy/<ipython console>

 /usr/lib/python2.4/site-packages/numpy/core/records.py in array(obj,
 dtype, shape, offset, strides, formats, names, titles, aligned, byteorder,
     516         copied = 0
     517         if dtype is not None and (obj.dtype != dtype):
 --> 518             new = obj.astype(dtype)
     519             copied = 1
     520         else:

 ValueError: size of tuple must match number of fields.


 i.e. in my opinion, 'nr' is a buffer that is compatible with both [('x',
 'i4'),('y','i4')] and [('new',[('x', 'i4'),('y','i4')])] datatypes, and
 there wouldn't be any harm in allowing this. I understand that allowing
 this in numpy.array would a bit controversial, but at least allowing it in
 numpy.rec.array would not create any secondary effect and this feature can
 be handy in some situations.

Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/318>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.

More information about the Numpy-tickets mailing list