给定一组点,如何在KDTree中获取它们的索引?
from scipy import spatial
import numpy as np
#some data
x, y = np.mgrid[0:3, 0:3]
data = zip(x.ravel(), y.ravel())
points = [[0,1], [2,2]]
#KDTree
tree = spatial.cKDTree(data)
# incices of points in tree should be [1,8]
我可以做类似这样的操作:
[tree.query_ball_point(i,r=0) for i in points]
>>> [[1], [8]]
用这种方式做有意义吗?