finding nearest neighbor for python numpy.ndarray in 3d-space

后端 未结 1 2000
我寻月下人不归
我寻月下人不归 2021-01-21 04:47

I have a numpy.ndarray of 3d-points, i.e. the np.shape of it is (4350,3) and such a second numpy.ndarray of 3d-points of np.shape (10510,3). Now I am trying to find the right p

相关标签:
1条回答
  • 2021-01-21 05:22

    Here is the KDTree way :

    from scipy.spatial import KDTree
    
    data= np.random.rand(10510,3)
    sample= np.random.rand(4350,3)
    kdtree=KDTree(data)
    

    Then dist,points=kdtree.query(sample,2) will give you the 2 best neighbors for the 4350 candidates in about one second.

    0 讨论(0)
提交回复
热议问题