Re: [Numpy-discussion] k maximal elements

2011-06-06 Thread RadimRehurek
> On Mon, Jun 6, 2011 at 6:57 AM, gary ruben 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-sm

Re: [Numpy-discussion] k maximal elements

2011-06-06 Thread Keith Goodman
On Mon, Jun 6, 2011 at 6:57 AM, gary ruben 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) > > import heapq > q = list(x) > heapq.heapify(q) > k_smallest = heapq.nsmalle

Re: [Numpy-discussion] k maximal elements

2011-06-06 Thread gary ruben
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) import heapq q = list(x) heapq.heapify(q) k_smallest = heapq.nsmallest(k,q) On Mon, Jun 6, 2011 at 10:52 PM, Olivier Delalleau wrote

Re: [Numpy-discussion] k maximal elements

2011-06-06 Thread Keith Goodman
On Mon, Jun 6, 2011 at 6:44 AM, Keith Goodman wrote: > On Sun, Jun 5, 2011 at 11:15 PM, Alex Ter-Sarkissov > wrote: >> I have a vector of positive integers length n. Is there a simple (i.e. >> without sorting/ranking) of 'pulling out' k larrgest (or smallest) values. >> Something like >> >> sum(

Re: [Numpy-discussion] k maximal elements

2011-06-06 Thread Keith Goodman
On Sun, Jun 5, 2011 at 11:15 PM, Alex Ter-Sarkissov wrote: > I have a vector of positive integers length n. Is there a simple (i.e. > without sorting/ranking) of 'pulling out' k larrgest (or smallest) values. > Something like > > sum(x[sum(x,1)>(max(sum(x,1)+min(sum(x,1/2,]) > > but smarter Y

Re: [Numpy-discussion] k maximal elements

2011-06-06 Thread David Cournapeau
On Mon, Jun 6, 2011 at 3:15 PM, Alex Ter-Sarkissov wrote: > I have a vector of positive integers length n. Is there a simple (i.e. > without sorting/ranking) of 'pulling out' k larrgest (or smallest) values. Maybe not so simple, but does not require sorting (and its associated o(NlogN) cost): htt

Re: [Numpy-discussion] k maximal elements

2011-06-06 Thread Olivier Delalleau
I don't really understand your proposed solution, but you can do something like: import heapq q = list(x) heapq.heapify(q) k_smallest = [heapq.heappop(q) for i in xrange(k)] which is in O(n + k log n) -=- Olivier 2011/6/6 Alex Ter-Sarkissov > I have a vector of positive integers length n. Is

[Numpy-discussion] k maximal elements

2011-06-05 Thread Alex Ter-Sarkissov
I have a vector of positive integers length n. Is there a simple (i.e. without sorting/ranking) of 'pulling out' k larrgest (or smallest) values. Something like *sum(x[sum(x,1)>(max(sum(x,1)+min(sum(x,1/2,])* but smarter ___ NumPy-Discussion mailing