【发布时间】:2016-02-22 18:21:48
【问题描述】:
给定一个点列表,我如何在 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]]
这样做有意义吗?
【问题讨论】: