bundles / scipy latest / scipy / cluster / hierarchy / weighted
function
scipy.cluster.hierarchy:weighted
source: /scipy/cluster/hierarchy.py :421
Signature
def weighted ( y ) Summary
Perform weighted/WPGMA linkage on the condensed distance matrix.
Extended Summary
See linkage for more information on the return structure and algorithm.
Parameters
y: ndarrayThe upper triangular of the distance matrix. The result of
pdistis returned in this form.
Returns
Z: ndarrayA linkage matrix containing the hierarchical clustering. See
linkagefor more information on its structure.
Notes
Array API Standard Support
weighted 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 weighted, 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 = weighted(y)
✓Z
✗fcluster(Z, 0.9, criterion='distance') fcluster(Z, 1.5, criterion='distance') fcluster(Z, 4, criterion='distance') fcluster(Z, 6, criterion='distance')✓
See also
- linkage
for advanced creation of hierarchical clusterings.
- scipy.spatial.distance.pdist
pairwise distance metrics
Aliases
-
scipy.cluster.hierarchy.weighted