NumPy proposes a way to get the index of the maximum value of an array via `np.argmax`

.

I would like a similar thing, but returning the indexes of the `N`

maximum values.

For instance, if I have an array, `[1, 3, 2, 4, 5]`

, `function(array, n=3)`

would return the indices `[4, 3, 1]`

which correspond to the elements `[5, 4, 3]`

.

The simplest I've been able to come up with is:

This involves a complete sort of the array. I wonder if

`numpy`

provides a built-in way to do a partial sort; so far I haven't been able to find one.If this solution turns out to be too slow (especially for small

`n`

), it may be worth looking at coding something up in Cython.