[Numpy-discussion] 1D array sorting ascending and descending by fields
Mon Jun 4 19:17:13 CDT 2012
On Monday, June 4, 2012, Chris Barker wrote:
> > Here's how I sorted primarily by field 'a' descending and secondarily by
> > field 'b' ascending:
> could you multiply the numeric field by -1, sort, then put it back --
> somethign like:
> data *- -1
> data_sorted = np.sort(data, order=['a','b'])
> data_sorted *= -1
> (reverse if necessary -- I lost track...)
While that may work for this users case, that would not work for all
dtypes. Some, such as timedelta, datetime and strings would not be able to
be multiplied by a number.
Would be an interesting feature to add, but I am not certain if the
negative sign notation would be best. Is it possible for a named field to
start with a negative sign?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion