[NumPy-Tickets] [NumPy] #1431: accessing multiple fields in a recarray gives fields in wrong order
NumPy Trac
numpy-tickets@scipy....
Tue Mar 16 11:44:12 CDT 2010
#1431: accessing multiple fields in a recarray gives fields in wrong order
------------------------+---------------------------------------------------
Reporter: samtygier | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone:
Component: numpy.core | Version:
Keywords: |
------------------------+---------------------------------------------------
when using the list in list notation to access multiple columns of a
record array the columns are returned in the order that they are stored in
the array, not in the order asked for.
{{{
>>> x = np.array([(1.5,2.5,(1.0,2.0)),(3.,4.,(4.,5.)),(1.,3.,(2.,6.))],
dtype=[('x','f4'),('y',np.float32),('value','f4',(2,2))])
>>> x[['x','y']]
array([(1.5, 2.5), (3.0, 4.0), (1.0, 3.0)],
dtype=[('x', '<f4'), ('y', '<f4')])
>>> x[['y','x']]
array([(1.5, 2.5), (3.0, 4.0), (1.0, 3.0)],
dtype=[('x', '<f4'), ('y', '<f4')])
}}}
this different to what happens with a 2d array, where they are returned in
the order asked for:
{{{
>>> a = array([0,0.1,0.2,0.3,0.4])
then
>>> a[[0,1,4]]
array([ 0. , 0.1, 0.4])
>>> a[[4,1,0]]
array([ 0.4, 0.1, 0. ])
}}}
I suggest that the it would be more consistent and predictable for the
order to be the one asked for in both cases.
The current behaviour for the recarray was undocumented until today, so
there can't be many people using it. therefore it might be worth break
backwards compatibility to make the interface better.
Please see discussion at
http://thread.gmane.org/gmane.comp.python.numeric.general/36933
a simple patch is attached.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1431>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list