bundles / scipy 1.17.1 / scipy / cluster / hierarchy / median
function
scipy.cluster.hierarchy:median
source: /scipy/cluster/hierarchy.py :610
Signature
def median ( y ) Summary
Perform median/WPGMC linkage.
Extended Summary
See linkage for more information on the return structure and algorithm.
The following are common calling conventions:
Z = median(y)Performs median/WPGMC linkage on the condensed distance matrix
y. Seelinkagefor more information on the return structure and algorithm.
Z = median(X)Performs median/WPGMC linkage on the observation matrix
Xusing Euclidean distance as the distance metric. Seelinkagefor more information on the return structure and algorithm.
Parameters
y: ndarrayA condensed distance matrix. A condensed distance matrix is a flat array containing the upper triangular of the distance matrix. This is the form that
pdistreturns. Alternatively, a collection of m observation vectors in n dimensions may be passed as an m by n array.
Returns
Z: ndarrayThe hierarchical clustering encoded as a linkage matrix.
Notes
Array API Standard Support
median 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 median, fcluster 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]]✓
y = pdist(X)
✓Z = median(y)
✓Z
✗fcluster(Z, 0.9, criterion='distance') fcluster(Z, 1.1, criterion='distance') fcluster(Z, 2, criterion='distance') fcluster(Z, 4, criterion='distance')✓
See also
- linkage
for advanced creation of hierarchical clusterings.
- scipy.spatial.distance.pdist
pairwise distance metrics
Aliases
-
scipy.cluster.hierarchy.median