bundles / scipy 1.17.1 / scipy / cluster / hierarchy / leaves_list
function
scipy.cluster.hierarchy:leaves_list
Signature
def leaves_list ( Z ) Summary
Return a list of leaf node ids.
Extended Summary
The return corresponds to the observation vector index as it appears in the tree from left to right. Z is a linkage matrix.
Parameters
Z: ndarrayThe hierarchical clustering encoded as a matrix.
Zis a linkage matrix. Seelinkagefor more information.
Returns
leaves_list: ndarrayThe list of leaf node ids.
Notes
Array API Standard Support
leaves_list 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
from scipy.cluster.hierarchy import ward, dendrogram, leaves_list from scipy.spatial.distance import pdist from matplotlib import pyplot as plt✓
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 = ward(pdist(X))
✓leaves_list(Z)
✓fig = plt.figure(figsize=(25, 10)) dn = dendrogram(Z) plt.show()✓

See also
- dendrogram
for information about dendrogram structure.
Aliases
-
scipy.cluster.hierarchy.leaves_list