Distance computations (scipy.spatial.distance
)¶
Function Reference¶
Distance matrix computation from a collection of raw observation vectors stored in a rectangular array.

Pairwise distances between observations in ndimensional space. 

Compute distance between each pair of the two collections of inputs. 

Convert a vectorform distance vector to a squareform distance matrix, and viceversa. 

Compute the directed Hausdorff distance between two ND 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.

Return True if input array is a valid distance matrix. 

Return True if the input array is a valid condensed distance matrix. 

Return the number of original observations that correspond to a square, redundant distance matrix. 

Return 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.

Compute the BrayCurtis distance between two 1D arrays. 

Compute the Canberra distance between two 1D arrays. 

Compute the Chebyshev distance. 

Compute the City Block (Manhattan) distance. 

Compute the correlation distance between two 1D arrays. 

Compute the Cosine distance between 1D arrays. 

Computes the Euclidean distance between two 1D arrays. 

Compute the JensenShannon distance (metric) between two 1D probability arrays. 

Compute the Mahalanobis distance between two 1D arrays. 

Compute the Minkowski distance between two 1D arrays. 

Return the standardized Euclidean distance between two 1D arrays. 

Compute the squared Euclidean distance between two 1D arrays. 

Compute the weighted Minkowski distance between two 1D 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.

Compute the Dice dissimilarity between two boolean 1D arrays. 

Compute the Hamming distance between two 1D arrays. 

Compute the JaccardNeedham dissimilarity between two boolean 1D arrays. 

Compute the Kulsinski dissimilarity between two boolean 1D arrays. 

Compute the RogersTanimoto dissimilarity between two boolean 1D arrays. 

Compute the RussellRao dissimilarity between two boolean 1D arrays. 

Compute the SokalMichener dissimilarity between two boolean 1D arrays. 

Compute the SokalSneath dissimilarity between two boolean 1D arrays. 

Compute the Yule dissimilarity between two boolean 1D arrays. 
hamming
also operates over discrete numerical vectors.