bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / cluster / hierarchy / _hierarchy_impl / is_isomorphic
function
scipy.cluster.hierarchy._hierarchy_impl:is_isomorphic
source: build-install/usr/lib/python3.14/site-packages/scipy/cluster/hierarchy/_hierarchy_impl.py:3715
Signature
def is_isomorphic(T1, T2)Summary
Determine if two different cluster assignments are equivalent.
Parameters
T1: array_likeAn assignment of singleton cluster ids to flat cluster ids.
T2: array_likeAn assignment of singleton cluster ids to flat cluster ids.
Returns
b: boolWhether the flat cluster assignments
T1andT2are equivalent.
Examples
from scipy.cluster.hierarchy import fcluster, is_isomorphic from scipy.cluster.hierarchy import single, complete 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]]✓
Z = single(pdist(X)) T = fcluster(Z, 1, criterion='distance') T✓
array([3, 3, 3, 4, 4, 4, 2, 2, 2, 1, 1, 1], dtype=int32)We can then do the same using the `scipy.cluster.hierarchy.complete`: method:
Z = complete(pdist(X)) T_ = fcluster(Z, 1.5, criterion='distance') T_✓
array([1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4], dtype=int32)As we can see, in both cases we obtain four clusters and all the data points are distributed in the same way - the only thing that changes are the flat cluster labels (3 => 1, 4 =>2, 2 =>3 and 4 =>1), so both cluster assignments are isomorphic:
is_isomorphic(T, T_)
✗np.True_
See also
Aliases
scipy.cluster.hierarchy.is_isomorphic