[SciPy-dev] Unexpected behavior getting fields from a structured array

Skipper Seabold jsseabold at gmail.com
Fri Nov 6 19:26:29 EST 2009


All,

I just got bit by this and was curious if this is just a limitation of
structured arrays.

import numpy as np
dt = [('var1', 'f'),('var2','f'),('var3','f')]
a = np.array([(1,3.5,0),(1,2.5,1),(3,4,1)], dtype=dt)
a[['var2','var3','var1']].view('f').reshape(3,3)

Out[100]:
array([[ 1. ,  3.5,  0. ],
       [ 1. ,  2.5,  1. ],
       [ 3. ,  4. ,  1. ]], dtype=float32)


I expected this to give me the fields in the order I asked for them,
but I got the fields in the order they occur.  Based on recent
discussions I guess this makes sense, so this might just be something
to look out for?

Skipper



More information about the SciPy-Dev mailing list