[Numpy-discussion] numpy rec array and sorting
washakie at gmail.com
Mon Dec 6 09:21:18 EST 2010
Hello, I have been trying two methods for creating a rec array from my
data (or a structured array -- I'm still not completely clear on the
distinction). In terms of data, you can see what types they are,
basically simple (n,1) np.ndarrays. I had to reshape them to (n,1) to
get them to work with hstack.
The 'NON WORKING' method returns no errors, but when I go to 'sort'
the data array that is returned, no sorting takes place, whereas with
the 'WORKING' method, I can do: data.sort(order='sza') and my
data.indices match the sorted 'sza' data. You can see I also tried to
include a 2-d array, but I haven't managed to get this to work...
Could someone please explain what is going on here?
## Create recarray so we can easily sort
### WORKING METHOD
values = np.hstack((indices,time,zen,az,sza,saz,musl,roll,pitch,yaw))
data = [ for dummy in xrange(len(dtype))]
for i in xrange(len(dtype)):
data[i] = cast[dtype[i]](values[:,i])
data = np.rec.array(data,dtype=dtype)
### NON WORKING METHOD ###
values = (indices,time,zen,az,sza,saz,musl,roll,pitch,yaw)
data = np.rec.fromarrays(values,dtype=dtype)
More information about the NumPy-Discussion