KDTree Python实现细节

时间:2015-06-30 23:40:42

标签: python algorithm tree scipy binary-tree

我正在调查scipy库中的KDTree实现,并发现自己有点混淆https://github.com/scipy/scipy/blob/master/scipy/spatial/kdtree.py#L314-L319

side_distances = np.maximum(0,np.maximum(x-self.maxes,self.mins-x))
if p != np.inf:
    side_distances **= p
    min_distance = np.sum(side_distances)
else:
    min_distance = np.amax(side_distances)

有人可以解释为什么以这种方式计算初始min_distance吗?

1 个答案:

答案 0 :(得分:1)

min_distanceside_distances的{​​{3}},它是从x到边界框(内部)的每个维度的距离。换句话说,min_distance是从x到边界框最近点的距离。