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 <[email protected]> > 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 list > [email protected] > http://mail.scipy.org/mailman/listinfo/numpy-discussion > >
_______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
