{ } Raw JSON

bundles / scipy 1.17.1 / scipy / cluster / hierarchy / num_obs_linkage

function

scipy.cluster.hierarchy:num_obs_linkage

source: /scipy/cluster/hierarchy.py :2417

Signature

def   num_obs_linkage ( Z )

Summary

Return the number of original observations of the linkage matrix passed.

Parameters

Z : ndarray

The linkage matrix on which to perform the operation.

Returns

n : int

The number of original observations in the linkage.

Notes

Array API Standard Support

num_obs_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                  ✅                     n/a                 
====================  ====================  ====================

See dev-arrayapi for more information.

Examples

from scipy.cluster.hierarchy import ward, num_obs_linkage
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 = ward(pdist(X))
``Z`` is a linkage matrix obtained after using the Ward clustering method with ``X``, a dataset with 12 data points.
num_obs_linkage(Z)

Aliases

  • scipy.cluster.hierarchy.num_obs_linkage