What is our equivalent of numpy.argpartition?

What is the julia equivalent of numpy’s argpartition?

Here is how it works:
Let’s say you want to get the indices of the top five entries of an array.
As an example, say I have probabilites of n events stored in an array. Now I want to find the index of the top five most likely events. I would do so in numpy:

indices_of_most_likely_5 = np.argpartition(probabilities, -5)[-5:]

It is based on the partition function:

least_5_at_the_beginning = np.partition(probabilities, 5)

This will partially sort probabilities so that the least five values are at the beginning and the rest later.

It does not sort the whole array, thus saving a lot of time O(n) vs O(n log(n)).

Thank you.

partialsortperm(probabilities, 1:5, rev=true)
4 Likes