bundles / scipy latest / scipy / cluster / hierarchy / correspond
function
scipy.cluster.hierarchy:correspond
Signature
def correspond ( Z , Y ) Summary
Check for correspondence between linkage and condensed distance matrices.
Extended Summary
They must have the same number of original observations for the check to succeed.
This function is useful as a sanity check in algorithms that make extensive use of linkage and distance matrices that must correspond to the same set of original observations.
Parameters
Z: array_likeThe linkage matrix to check for correspondence.
Y: array_likeThe condensed distance matrix to check for correspondence.
Returns
b: boolA boolean indicating whether the linkage matrix and distance matrix could possibly correspond to one another.
Notes
Array API Standard Support
correspond has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ✅ JAX ✅ ✅ Dask ✅ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
from scipy.cluster.hierarchy import ward, correspond from scipy.spatial.distance import pdist✓
X = [[0, 0], [0, 1], [1, 0], [0, 4], [0, 3], [1, 4], [4, 0], [3, 0], [4, 1], [4, 4], [3, 4], [4, 3]] X_condensed = pdist(X) Z = ward(X_condensed)✓
correspond(Z, X_condensed)
✓See also
- linkage
for a description of what a linkage matrix is.
Aliases
-
scipy.cluster.hierarchy.correspond