# 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]) Pairwise distances between 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 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) Computes the Bray-Curtis distance between two 1-D arrays. canberra(u, v) Computes the Canberra distance between two 1-D arrays. chebyshev(u, v) Computes the Chebyshev distance. cityblock(u, v) Computes the City Block (Manhattan) distance. correlation(u, v) Computes the correlation distance between two 1-D arrays. cosine(u, v) Computes the Cosine distance between 1-D arrays. euclidean(u, v) 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) 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) 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) Computes the Dice dissimilarity between two boolean 1-D arrays. hamming(u, v) Computes the Hamming distance between two 1-D arrays. jaccard(u, v) Computes the Jaccard-Needham dissimilarity between two boolean 1-D arrays. kulsinski(u, v) Computes the Kulsinski dissimilarity between two boolean 1-D arrays. matching(u, v) Computes the Hamming distance between two boolean 1-D arrays. rogerstanimoto(u, v) Computes the Rogers-Tanimoto dissimilarity between two boolean 1-D arrays. russellrao(u, v) Computes the Russell-Rao dissimilarity between two boolean 1-D arrays. sokalmichener(u, v) Computes the Sokal-Michener dissimilarity between two boolean 1-D arrays. sokalsneath(u, v) Computes the Sokal-Sneath dissimilarity between two boolean 1-D arrays. yule(u, v) Computes the Yule dissimilarity between two boolean 1-D arrays.

hamming also operates over discrete numerical vectors.
{"ft_lang_label":"__label__en","ft_lang_prob":0.7806864,"math_prob":0.9958008,"size":3305,"snap":"2019-13-2019-22","text_gpt3_token_len":852,"char_repetition_ratio":0.26295063,"word_repetition_ratio":0.117117114,"special_character_ratio":0.22027232,"punctuation_ratio":0.15166667,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9980011,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-03-24T02:24:49Z\",\"WARC-Record-ID\":\"<urn:uuid:03850450-1493-41d8-aa81-3431d7e50e10>\",\"Content-Length\":\"18695\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:85505b51-7c41-4d85-ba75-a215acca15d6>\",\"WARC-Concurrent-To\":\"<urn:uuid:4af6949b-c4a7-47ba-84e9-498c69d01b69>\",\"WARC-IP-Address\":\"50.17.248.72\",\"WARC-Target-URI\":\"https://docs.scipy.org/doc/scipy-0.18.1/reference/spatial.distance.html\",\"WARC-Payload-Digest\":\"sha1:TF2TQKMWF4L2XJCX7MZNYYCYPZTVNU2W\",\"WARC-Block-Digest\":\"sha1:7EDSJ36TZCDMD2Z43MH46WM7J2NGELMM\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-13/CC-MAIN-2019-13_segments_1552912203168.70_warc_CC-MAIN-20190324022143-20190324044143-00507.warc.gz\"}"}