[Numpy-discussion] why sort does not accept a key?

josef.pktd at gmail.com josef.pktd at gmail.com
Mon Mar 24 12:13:02 EDT 2014


On Mon, Mar 24, 2014 at 12:08 PM, Alan G Isaac <alan.isaac at gmail.com> wrote:
>> On Mon, Mar 24, 2014 at 11:32 AM, Alan G Isaac wrote:
>>>     I'm wondering if `sort` intentionally does not accept
>>>     a `key`
>>>     or if this is just a missing feature?
>
>
> On 3/24/2014 11:47 AM, Alexander Belopolsky wrote:
>> It would be very inefficient to call a key function on
>> every element compared during the sort.   See np.argsort
>> and np.lexsort for faster alternatives.
>
>
> But the keys could be as in `lexsort`.
>
> I am currently using `argsort`, but I can do so because
> I don't need a lexicographically determined sort order
> for the indexes.
>
>
> To close with a related question:
> what is the preferred idiom for a descending sort?

adding [::-1] just creates a new view, pretty low cost.

Josef


>
> Thanks,
> Alan
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion



More information about the NumPy-Discussion mailing list