[Numpy-discussion] Find the N maximum values and corresponding indexes in an array

Charles R Harris charlesr.harris@gmail....
Thu Dec 3 11:34:18 CST 2009


On Thu, Dec 3, 2009 at 10:24 AM, Howard Chong <hgchong@berkeley.edu> wrote:

> Thanks for all the help and suggestions. I think the partial sort is
> exactly what I need.
>
> I thought of doing it as a full sort with argsort(), but that would be much
> slower if I just need a small number (maybe 7) from a large array,
> potentially thousands or a million repeated many times.
>
> In case you are wondering, I am doing this to find the 7 nearest neighbors
> in a GIS. For a list of zipcodes in America, find the 7 nearest weather
> stations.
>
>

Have you looked at the kdtree in scipy? It is aimed precisely at this sort
of problem.

<snip>

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20091203/0020b7e7/attachment.html 


More information about the NumPy-Discussion mailing list