[SciPy-user] one-liner to retrieve indices of n smallest values from an array?
Robert Kern
robert.kern at gmail.com
Tue Oct 17 23:52:51 EDT 2006
Aaron Hoover wrote:
> Hi all,
>
> Perhaps this is better suited for the NumPy list, but is there a
> simple (one line, perhaps) way to get the indices of the n smallest
> elements of an array? Something along the lines of argmin() that
> could take a parameter indicating
> how many minimal values to return?
a.argsort()[:n]
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the SciPy-User
mailing list