> 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
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
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
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(
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
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
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
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