[Numpy-discussion] sort bug

Robert Kern robert.kern at gmail.com
Thu Apr 26 15:25:47 EDT 2007


tan2 wrote:
> 
>     On 4/26/07, * Anton Sherwood* <anton.sherwood at gmail.com
>     <mailto:anton.sherwood at gmail.com>> wrote:
> 
>         All I really need is the four highest eigenvalues and their
>         vectors.
>         I'll have a look in "Python Cookbook" to see if there's a more
>         efficient way to do that partial sort.
> 
> Maybe "heapq.nlargest ()" is what you want?
> http://www.python.org/doc/2.4/lib/module-heapq.html

Just doing argsort() on the whole array is faster (up until about 1e6 elements)
because it does everything in C whereas heapq will create a lot of Python
objects because it is treating the array as a general Python container.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list