[SciPy-User] Finding closest point in array - inverse of KDTree
davidmenhur at gmail.com
Thu Oct 12 10:16:27 EDT 2017
On 12 October 2017 at 15:18, Ant <antoniy.py at gmail.com> wrote:
> Thank you! This indeed is twice as fast as doing it normally (not counting
> the fixed time of sorting A, of course).
> I would still like to speed it up, getting another 2x speedup. This is my
> code, please tell me if you have any suggestions!
As always, when optimising you must profile. For A of size 3000000 and k of
size 30, this is what I get:
89% of the time is being spent on this line (and it gets worse as you
increase the size of A):
indicesClosest = final_indices[inv_idx_sort]
I don't know from the top of my head of a faster way of doing this, so, can
you somehow adapt your problem to use your sorted indexes of A instead?
This you can very easily rewrite unrolled in Cython, I think you can scrape
a bit of time there.
Here is a good tutorial for Numpy:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User