scipy.spatial.distance

Distance computations (scipy.spatial.distance)

Function Reference

Distance matrix computation from a collection of raw observation vectors stored in a rectangular array.

pdist(X[, metric, p, w, V, VI]) Computes the pairwise distances between m original observations in n-dimensional space.
cdist(XA, XB[, metric, p, V, VI, w]) Computes distance between each pair of the two collections of inputs.
squareform(X[, force, checks]) Converts a vector-form distance vector to a square-form distance matrix, and vice-versa.

Predicates for checking the validity of distance matrices, both condensed and redundant. Also contained in this module are functions for computing the number of observations in a distance matrix.

is_valid_dm(D[, tol, throw, name, warning]) Returns True if the variable D passed is a valid distance matrix.
is_valid_y(y[, warning, throw, name]) Returns True if the variable y passed is a valid condensed
num_obs_dm(d) Returns the number of original observations that correspond to a
num_obs_y(Y) Returns the number of original observations that correspond to a

Distance functions between two vectors u and v. Computing distances over a large collection of vectors is inefficient for these functions. Use pdist for this purpose.

braycurtis(u, v) Computes the Bray-Curtis distance between two n-vectors u and
canberra(u, v) Computes the Canberra distance between two n-vectors u and v,
chebyshev(u, v) Computes the Chebyshev distance between two n-vectors u and v,
cityblock(u, v) Computes the Manhattan distance between two n-vectors u and v,
correlation(u, v) Computes the correlation distance between two n-vectors u and v, which is defined as ..
cosine(u, v) Computes the Cosine distance between two n-vectors u and v, which
dice(u, v) Computes the Dice dissimilarity between two boolean n-vectors
euclidean(u, v) Computes the Euclidean distance between two n-vectors u and v,
hamming(u, v) Computes the Hamming distance between two n-vectors u and
jaccard(u, v) Computes the Jaccard-Needham dissimilarity between two boolean
kulsinski(u, v) Computes the Kulsinski dissimilarity between two boolean n-vectors
mahalanobis(u, v, VI) Computes the Mahalanobis distance between two n-vectors u and v,
matching(u, v) Computes the Matching dissimilarity between two boolean n-vectors
minkowski(u, v, p) Computes the Minkowski distance between two vectors u and v,
rogerstanimoto(u, v) Computes the Rogers-Tanimoto dissimilarity between two boolean
russellrao(u, v) Computes the Russell-Rao dissimilarity between two boolean n-vectors
seuclidean(u, v, V) Returns the standardized Euclidean distance between two n-vectors
sokalmichener(u, v) Computes the Sokal-Michener dissimilarity between two boolean vectors
sokalsneath(u, v) Computes the Sokal-Sneath dissimilarity between two boolean vectors
sqeuclidean(u, v) Computes the squared Euclidean distance between two n-vectors u and v,
yule(u, v) Computes the Yule dissimilarity between two boolean n-vectors u and v,

Functions

braycurtis(u, v) Computes the Bray-Curtis distance between two n-vectors u and
canberra(u, v) Computes the Canberra distance between two n-vectors u and v,
cdist(XA, XB[, metric, p, V, VI, w]) Computes distance between each pair of the two collections of inputs.
chebyshev(u, v) Computes the Chebyshev distance between two n-vectors u and v,
cityblock(u, v) Computes the Manhattan distance between two n-vectors u and v,
correlation(u, v) Computes the correlation distance between two n-vectors u and v, which is defined as ..
cosine(u, v) Computes the Cosine distance between two n-vectors u and v, which
dice(u, v) Computes the Dice dissimilarity between two boolean n-vectors
euclidean(u, v) Computes the Euclidean distance between two n-vectors u and v,
hamming(u, v) Computes the Hamming distance between two n-vectors u and
is_valid_dm(D[, tol, throw, name, warning]) Returns True if the variable D passed is a valid distance matrix.
is_valid_y(y[, warning, throw, name]) Returns True if the variable y passed is a valid condensed
jaccard(u, v) Computes the Jaccard-Needham dissimilarity between two boolean
kulsinski(u, v) Computes the Kulsinski dissimilarity between two boolean n-vectors
mahalanobis(u, v, VI) Computes the Mahalanobis distance between two n-vectors u and v,
matching(u, v) Computes the Matching dissimilarity between two boolean n-vectors
minkowski(u, v, p) Computes the Minkowski distance between two vectors u and v,
norm(x[, ord]) Matrix or vector norm.
num_obs_dm(d) Returns the number of original observations that correspond to a
num_obs_y(Y) Returns the number of original observations that correspond to a
pdist(X[, metric, p, w, V, VI]) Computes the pairwise distances between m original observations in n-dimensional space.
rogerstanimoto(u, v) Computes the Rogers-Tanimoto dissimilarity between two boolean
russellrao(u, v) Computes the Russell-Rao dissimilarity between two boolean n-vectors
seuclidean(u, v, V) Returns the standardized Euclidean distance between two n-vectors
sokalmichener(u, v) Computes the Sokal-Michener dissimilarity between two boolean vectors
sokalsneath(u, v) Computes the Sokal-Sneath dissimilarity between two boolean vectors
sqeuclidean(u, v) Computes the squared Euclidean distance between two n-vectors u and v,
squareform(X[, force, checks]) Converts a vector-form distance vector to a square-form distance matrix, and vice-versa.
wminkowski(u, v, p, w) Computes the weighted Minkowski distance between two vectors u
yule(u, v) Computes the Yule dissimilarity between two boolean n-vectors u and v,

Table Of Contents

Previous topic

scipy.spatial.cKDTree.query

Next topic

scipy.spatial.distance.pdist