scipy 1.8.0 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
squareform(X, force='no', checks=True)

Notes

  1. v = squareform(X)

    Given a square n-by-n symmetric distance matrix X , v = squareform(X) returns a n * (n-1) / 2 (i.e. binomial coefficient n choose 2) sized vector :None:None:`v` where $v[{n \choose 2} - {n-i \choose 2} + (j-i-1)]$ is the distance between distinct points i and j . If X is non-square or asymmetric, an error is raised.

  2. X = squareform(v)

    Given a n * (n-1) / 2 sized vector v for some integer n >= 1 encoding distances as described, X = squareform(v) returns a n-by-n distance matrix X . The X[i, j] and X[j, i] values are set to $v[{n \choose 2} - {n-i \choose 2} + (j-i-1)]$ and all diagonal elements are zero.

In SciPy 0.19.0, squareform stopped casting all input types to float64, and started returning arrays of the same dtype as the input.

Parameters

X : array_like

Either a condensed or redundant distance matrix.

force : str, optional

As with MATLAB(TM), if force is equal to 'tovector' or 'tomatrix' , the input will be treated as a distance matrix or distance vector respectively.

checks : bool, optional

If set to False, no checks will be made for matrix symmetry nor zero diagonals. This is useful if it is known that X - X.T1 is small and diag(X) is close to zero. These values are ignored any way so they do not disrupt the squareform transformation.

Returns

Y : ndarray

If a condensed distance matrix is passed, a redundant one is returned, or if a redundant one is passed, a condensed distance matrix is returned.

Convert a vector-form distance vector to a square-form distance matrix, and vice-versa.

Examples

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.spatial.distance.pdist

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/spatial/distance.py#2267
type: <class 'function'>
Commit: