bundles / scipy latest / scipy / cluster / hierarchy / from_mlab_linkage
function
scipy.cluster.hierarchy:from_mlab_linkage
Signature
def from_mlab_linkage ( Z ) Summary
Convert a linkage matrix generated by MATLAB(TM) to a new linkage matrix compatible with this module.
Extended Summary
The conversion does two things:
the indices are converted from
1..Nto0..(N-1)form, anda fourth column
Z[:,3]is added whereZ[i,3]represents the number of original observations (leaves) in the non-singleton clusteri.
This function is useful when loading in linkages from legacy data files generated by MATLAB.
Parameters
Z: ndarrayA linkage matrix generated by MATLAB(TM).
Returns
ZS: ndarrayA linkage matrix compatible with
scipy.cluster.hierarchy.
Notes
Array API Standard Support
from_mlab_linkage 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 ⚠️ merges chunks n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
import numpy as np from scipy.cluster.hierarchy import ward, from_mlab_linkage✓
mZ = np.array([[1, 2, 1], [4, 5, 1], [7, 8, 1], [10, 11, 1], [3, 13, 1.29099445], [6, 14, 1.29099445], [9, 15, 1.29099445], [12, 16, 1.29099445], [17, 18, 5.77350269], [19, 20, 5.77350269], [21, 22, 8.16496581]])✓
Z = from_mlab_linkage(mZ)
✓Z
✗See also
- linkage
for a description of what a linkage matrix is.
- to_mlab_linkage
transform from SciPy to MATLAB format.
Aliases
-
scipy.cluster.hierarchy.from_mlab_linkage