Efficiently Calculating a Euclidean Distance Matrix Using Numpy

后端 未结 4 481
我在风中等你
我在风中等你 2020-11-30 02:31

I have a set of points in 2-dimensional space and need to calculate the distance from each point to each other point.

I have a relatively small number of points, ma

4条回答
  •  無奈伤痛
    2020-11-30 03:21

    If you don't need the full distance matrix, you will be better off using kd-tree. Consider scipy.spatial.cKDTree or sklearn.neighbors.KDTree. This is because a kd-tree kan find k-nearnest neighbors in O(n log n) time, and therefore you avoid the O(n**2) complexity of computing all n by n distances.

提交回复
热议问题