Here's how I sorted primarily by field 'a' descending and secondarily by
field 'b' ascending:
(Note that 'a' is the second column, 'b' is the first)

>>> data
array([('b', 0.03),
       ('c', 0.03),
       ('f', 0.03),
       ('e', 0.01),
       ('d', 0.04),
       ('a', 0.04)],
      dtype=[('b', '|S32'), ('a', '<f8')])
>>> data.sort(order='b') # sort by b
>>> data = data[::-1] # reverse
>>> data[numpy.argsort(data['a'])][::-1] # sort by a and reverse
array([('a', 0.04),
       ('d', 0.04),
       ('b', 0.03),
       ('c', 0.03),
       ('f', 0.03),
       ('e', 0.01)],
      dtype=[('b', '|S32'), ('a', '<f8')])

My question is whether there's an easier way to do this. Originally I
thought it would be possible to just do:

>>> data.sort(order=('-a', 'b'))

...indicating that the order of 'a' is descending, but this isn't part of
NumPy's sort behavior.

Your help is appreciated!

Thank you,
Patrick
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to