Finding index of nearest point in numpy arrays of x and y coordinates

前端 未结 3 2119
陌清茗
陌清茗 2020-11-27 10:41

I have two 2d numpy arrays: x_array contains positional information in the x-direction, y_array contains positions in the y-direction.

I then have a long list of x,y

3条回答
  •  悲哀的现实
    2020-11-27 10:56

    scipy.spatial also has a k-d tree implementation: scipy.spatial.KDTree.

    The approach is generally to first use the point data to build up a k-d tree. The computational complexity of that is on the order of N log N, where N is the number of data points. Range queries and nearest neighbour searches can then be done with log N complexity. This is much more efficient than simply cycling through all points (complexity N).

    Thus, if you have repeated range or nearest neighbor queries, a k-d tree is highly recommended.

提交回复
热议问题