多个 SciPy 函数被记录为采用“scipy.spatial.distance.pdist
返回的压缩距离矩阵”。现在,检查表明 pdist 返回的是距离矩阵上部非对角部分的行主一维数组形式。这一切都很好,自然而明显,但是它在任何地方都有记录或定义吗?我不想对突然改变的数据结构做出任何假设。 (当然,它可以改变的东西并不多,但我想一种可能性是将数组包装在一个允许类似矩阵索引的对象中。)
最佳答案
老实说,对于 scipy 用户或开发者列表来说,这是一个更好的问题,因为它关系到 scipy 的 future 计划。
但是,该结构在 scipy.spatial.pdist 和 scipy.spatial.squareform 的文档字符串中都有相当严格的记录。
例如对于pdist
:
Returns a condensed distance matrix Y. For
each :math:`i` and :math:`j` (where :math:`i<j<n`), the
metric ``dist(u=X[i], v=X[j])`` is computed and stored in the
:math:`ij`th entry.
See ``squareform`` for information on how to calculate the index of
this entry or to convert the condensed distance matrix to a
redundant square matrix.
由于这一点,以及 scipy.spatial
中的许多其他函数都期望这种形式的距离矩阵,我严重怀疑它是否会在没有大量折旧警告的情况下发生变化公告。
scipy
本身的模块(相对于 scipy 的 scikits
)相当稳定,并且在进行更改时会大量考虑向后兼容性(并且因为其中,scipy 中有相当多的遗留“问题”:例如,核心 scipy 模块只是 numpy,在几个函数上有不同的默认值。) .
关于python - SciPy 的压缩距离矩阵的格式/结构稳定吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9394482/