Skip to content

argsort/sort with O(n) algorithms: counting-sort, radix-sort #6050

@d1manson

Description

@d1manson

You can already sort with couting-sort using numpy: as stated in an SO answer, it is simply:

np.repeat(np.arange(1+x.max()), np.bincount(x))

But there is no way (as far as I can tell) to do an argsort.

I think it would be fairly easy to implement and slot into the argsort/sort documentation. The benefit of counting sort is that it's O(n), although it only works for not-too-large non-negative integers...however those are actually quite common in the real world! Pandas uses it behind the scenes apparently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions