SciPy

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]) Pairwise distances between observations in n-dimensional space.
cdist(XA, XB[, metric]) 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.
directed_hausdorff(u, v[, seed]) Computes the directed Hausdorff distance between two N-D arrays.

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 input array is a valid distance matrix.
is_valid_y(y[, warning, throw, name]) Returns True if the input array is a valid condensed distance matrix.
num_obs_dm(d) Returns the number of original observations that correspond to a square, redundant distance matrix.
num_obs_y(Y) Returns the number of original observations that correspond to a condensed distance matrix.

Distance functions between two numeric 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[, w]) Computes the Bray-Curtis distance between two 1-D arrays.
canberra(u, v[, w]) Computes the Canberra distance between two 1-D arrays.
chebyshev(u, v) Computes the Chebyshev distance.
cityblock(u, v[, w]) Computes the City Block (Manhattan) distance.
correlation(u, v[, w, centered]) Computes the correlation distance between two 1-D arrays.
cosine(u, v[, w]) Computes the Cosine distance between 1-D arrays.
euclidean(u, v[, w]) Computes the Euclidean distance between two 1-D arrays.
mahalanobis(u, v, VI) Computes the Mahalanobis distance between two 1-D arrays.
minkowski(u, v[, p, w]) Computes the Minkowski distance between two 1-D arrays.
seuclidean(u, v, V) Returns the standardized Euclidean distance between two 1-D arrays.
sqeuclidean(u, v[, w]) Computes the squared Euclidean distance between two 1-D arrays.
wminkowski(u, v, p, w) Computes the weighted Minkowski distance between two 1-D arrays.

Distance functions between two boolean vectors (representing sets) u and v. As in the case of numerical vectors, pdist is more efficient for computing the distances between all pairs.

dice(u, v[, w]) Computes the Dice dissimilarity between two boolean 1-D arrays.
hamming(u, v[, w]) Computes the Hamming distance between two 1-D arrays.
jaccard(u, v[, w]) Computes the Jaccard-Needham dissimilarity between two boolean 1-D arrays.
kulsinski(u, v[, w]) Computes the Kulsinski dissimilarity between two boolean 1-D arrays.
rogerstanimoto(u, v[, w]) Computes the Rogers-Tanimoto dissimilarity between two boolean 1-D arrays.
russellrao(u, v[, w]) Computes the Russell-Rao dissimilarity between two boolean 1-D arrays.
sokalmichener(u, v[, w]) Computes the Sokal-Michener dissimilarity between two boolean 1-D arrays.
sokalsneath(u, v[, w]) Computes the Sokal-Sneath dissimilarity between two boolean 1-D arrays.
yule(u, v[, w]) Computes the Yule dissimilarity between two boolean 1-D arrays.

hamming also operates over discrete numerical vectors.

Functions

braycurtis(u, v[, w]) Computes the Bray-Curtis distance between two 1-D arrays.
callable((object) -> bool) Return whether the object is callable (i.e., some kind of function).
canberra(u, v[, w]) Computes the Canberra distance between two 1-D arrays.
cdist(XA, XB[, metric]) Computes distance between each pair of the two collections of inputs.
chebyshev(u, v) Computes the Chebyshev distance.
cityblock(u, v[, w]) Computes the City Block (Manhattan) distance.
correlation(u, v[, w, centered]) Computes the correlation distance between two 1-D arrays.
cosine(u, v[, w]) Computes the Cosine distance between 1-D arrays.
dice(u, v[, w]) Computes the Dice dissimilarity between two boolean 1-D arrays.
directed_hausdorff(u, v[, seed]) Computes the directed Hausdorff distance between two N-D arrays.
euclidean(u, v[, w]) Computes the Euclidean distance between two 1-D arrays.
hamming(u, v[, w]) Computes the Hamming distance between two 1-D arrays.
is_valid_dm(D[, tol, throw, name, warning]) Returns True if input array is a valid distance matrix.
is_valid_y(y[, warning, throw, name]) Returns True if the input array is a valid condensed distance matrix.
jaccard(u, v[, w]) Computes the Jaccard-Needham dissimilarity between two boolean 1-D arrays.
kulsinski(u, v[, w]) Computes the Kulsinski dissimilarity between two boolean 1-D arrays.
mahalanobis(u, v, VI) Computes the Mahalanobis distance between two 1-D arrays.
matching(*args, **kwds) matching is deprecated!
minkowski(u, v[, p, w]) Computes the Minkowski distance between two 1-D arrays.
namedtuple(typename, field_names[, verbose, ...]) Returns a new subclass of tuple with named fields.
norm(a[, ord, axis, keepdims]) Matrix or vector norm.
num_obs_dm(d) Returns the number of original observations that correspond to a square, redundant distance matrix.
num_obs_y(Y) Returns the number of original observations that correspond to a condensed distance matrix.
pdist(X[, metric]) Pairwise distances between observations in n-dimensional space.
rogerstanimoto(u, v[, w]) Computes the Rogers-Tanimoto dissimilarity between two boolean 1-D arrays.
russellrao(u, v[, w]) Computes the Russell-Rao dissimilarity between two boolean 1-D arrays.
seuclidean(u, v, V) Returns the standardized Euclidean distance between two 1-D arrays.
sokalmichener(u, v[, w]) Computes the Sokal-Michener dissimilarity between two boolean 1-D arrays.
sokalsneath(u, v[, w]) Computes the Sokal-Sneath dissimilarity between two boolean 1-D arrays.
sqeuclidean(u, v[, w]) Computes the squared Euclidean distance between two 1-D arrays.
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 1-D arrays.
yule(u, v[, w]) Computes the Yule dissimilarity between two boolean 1-D arrays.

Classes

MetricInfo

Attributes

partial partial(func, *args, **keywords) - new function with partial application
xrange xrange(start, stop[, step]) -> xrange object