[Numpy-discussion] k maximal elements

RadimRehurek RadimRehurek at seznam.cz
Mon Jun 6 11:44:30 EDT 2011


> On Mon, Jun 6, 2011 at 6:57 AM, gary ruben <gruben at bigpond.net.au> wrote:
> > I learn a lot by watching the numpy and scipy lists (today Olivier
> > taught me about heapq :), but he may not have noticed that Python 2.4
> > added an nsmallest method)

I needed  indices of the selected elements as well (not just the k-smallest values themselves) some time ago and compared heapq vs. sort vs. numpy.argsort.

Timing results (for my specific usecase) are at https://github.com/piskvorky/gensim/issues/5 . The results are as expected: argsort is a must, forming (value, index) tuples explicitly and then sorting that with sort/heapq kills performance.

Best,
Radim



More information about the NumPy-Discussion mailing list