scipy.cKDTree.sparse_distance_matrix 的奇怪行为

Strange behavior of scipy.cKDTree.sparse_distance_matrix

我正在尝试使用 scipy.cKDTree.sparse_distance_matrix 计算一组点的相互距离。最终我想将它用于维度高达 1510**6 点,但作为示例,对于二维中的 15 个数据点,我们期望距离矩阵具有 15*15 个元素,其中其中 15 个为零。因此矩阵中有 210 个非零元素。但是 sparse_distance_matrix returns 只有 160 个非零值:

import numpy as np
from scipy.spatial import cKDTree
NP=15
dimension=2
seed=1
state = np.random.RandomState(seed)
pts=state.random_sample([NP,dimension]) 
tree=cKDTree(pts)
f = cKDTree.sparse_distance_matrix(tree,tree,5.)
print np.vstack(f.nonzero()).T.shape[0]

160

我不明白我错过了什么。请注意,我已将 max_distance 设置为 5.0,但可能的最长距离是 sqrt(2),因此不应将任何条目替换为零。我正在使用 SciPy 版本 '0.13.3`。

编辑:

更新到 0.16 解决了这个问题。

作为旧版本 scipy 中的@Warren Weckesser mentioned in his comment, this was due to an issue。在scipy 0.16一切都很好!