argpartsort

26 views
Skip to first unread message

dbv

unread,
Jun 25, 2013, 4:29:33 AM6/25/13
to bottl...@googlegroups.com
Hi! Need to part sort so that it returns top R and bottom R results.  Obvious solution is to bottleneck.argpartsort for top R followed by bottleneck.argpartsort for bottom R.  Is there a more efficient alternative?

Keith Goodman

unread,
Jun 25, 2013, 12:30:42 PM6/25/13
to bottl...@googlegroups.com
On Tue, Jun 25, 2013 at 1:29 AM, dbv <dinesh...@hotmail.com> wrote:

Hi! Need to part sort so that it returns top R and bottom R results.  Obvious solution is to bottleneck.argpartsort for top R followed by bottleneck.argpartsort for bottom R.  Is there a more efficient alternative?

It might depend on the sizes involved. If 2R == N then one partsort is all you need! If R << N then it will be hard to do a lot better than two sorts.

bn.partsort is probably a little faster than bn.argpartsort if you only need the values and not the indices. And if you use bn.partsort then you can use a slice of the sorted array a[R:] for the second sort. That should save some time if R is a decent fraction of N.

ipython's timeit will give you the answer. If you try a few methods then share the results with us.

dbv

unread,
Jun 26, 2013, 3:25:27 AM6/26/13
to bottl...@googlegroups.com
Uhmm.  Indices are needed plus R, N are variable.  Looks like two sorts will be needed.
Reply all
Reply to author
Forward
0 new messages