numpy rec array and sorting
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 dtype=np.dtype([('indices','int32'),('time','f8'),('zen','f4'),\ ('az','f4'),('sza','f4'),('saz','f4'),('muslope','f4'),\ ('roll','f4'),('pitch','f4'),('yaw','f4')\ #,('spectra',np.ma.core.MaskedArray,c.shape) ])
### 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)