Warning: This documentation is for scikits.learn version 0.7.1. — Latest stable version

Contents

6.9.1. scikits.learn.metrics.euclidean_distances

scikits.learn.metrics.euclidean_distances(X, Y, Y_norm_squared=None, squared=False)

Considering the rows of X (and Y=X) as vectors, compute the distance matrix between each pair of vectors.

Parameters :

X: array of shape (n_samples_1, n_features) :

Y: array of shape (n_samples_2, n_features) :

Y_norm_squared: array [n_samples_2], optional :

pre-computed (Y**2).sum(axis=1)

squared: boolean, optional :

This routine will return squared Euclidean distances instead.

Returns :

distances: array of shape (n_samples_1, n_samples_2) :

Examples

>>> from scikits.learn.metrics.pairwise import euclidean_distances
>>> X = [[0, 1], [1, 1]]
>>> # distrance between rows of X
>>> euclidean_distances(X, X)
array([[ 0.,  1.],
       [ 1.,  0.]])
>>> # get distance to origin
>>> euclidean_distances(X, [[0, 0]])
array([[ 1.        ],
       [ 1.41421356]])