我想使用 Scipy cKDTree 在一定距离内找到邻居。最重要的是,我也想要点本身(零距离)。cKD 树。查询给出所有邻居但没有零距离。
有没有办法做到这一点?
我无法真正重现您的问题(或者它可能取决于您用来查询树的方法)。
考虑这个简单的代码片段:
>>> from scipy.spatial import cKDTree
>>> import numpy as np
>>> points_ref = np.array([(1, 1), (3, 3), (4, 4), (5, 4), (6, 6)])
>>> tree = cKDTree(points_ref)
Run Code Online (Sandbox Code Playgroud)
使用该方法查询2点周围距离的最近邻居可以给出类似的结果:(4, 4)cKDTree.query_ball_point
>>> idx = tree.query_ball_point((4, 4), 2)
>>> points_ref[idx]
# array([[3, 3], [4, 4], [5, 4]])
Run Code Online (Sandbox Code Playgroud)
它返回距离为 0 的点。
使用该方法查询n 个最近邻cKDTree.query似乎也返回距离为 0 的点:
>>> _, idx = tree.query((3, 3), k=2)
>>> points_ref[idx]
# array([[3, 3], [4, 4]])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5603 次 |
| 最近记录: |