[Numpy-discussion] k maximal elements
Mon Jun 6 10:44:30 CDT 2011
> On Mon, Jun 6, 2011 at 6:57 AM, gary ruben <firstname.lastname@example.org> 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.
More information about the NumPy-Discussion