On Mon, Mar 24, 2014 at 11:05 AM, Alan G Isaac <[email protected]> wrote:

> > On Mon, Mar 24, 2014 at 12:08 PM, Alan G Isaac
> >> what is the preferred idiom for a descending sort?
>
>
> On 3/24/2014 12:13 PM, [email protected] wrote:
> > adding [::-1] just creates a new view, pretty low cost.
>
>
> I meant when you need to sort on a key (another vector).
>
> Currently I'm just reversing the result of argsort with [::-1]
> but this changes the sort order (relative to a stable descending sort).
>
>
For integer types you can use the complement as the key

In [9]: ~arange(4, dtype=uint8)
Out[9]: array([255, 254, 253, 252], dtype=uint8)

In [10]: ~arange(4, dtype=int8)
Out[10]: array([-1, -2, -3, -4], dtype=int8)

For float types you would need to use the negative.

Chuck
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to