Compute cosine distance between samples in X and Y.
Cosine distance is defined as 1.0 minus the cosine similarity.
Read more in the User Guide.
Matrix X.
Matrix Y.
Returns the cosine distance between samples in X and Y.
See also
cosine_similarityCompute cosine similarity between samples in X and Y.
scipy.spatial.distance.cosineDense matrices only.
>>> from sklearn.metrics.pairwise import cosine_distances
>>> X = [[0, 0, 0], [1, 1, 1]]
>>> Y = [[1, 0, 0], [1, 1, 0]]
>>> cosine_distances(X, Y)
array([[1. , 1. ],
[0.42..., 0.18...]])
© 2007–2025 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.6/modules/generated/sklearn.metrics.pairwise.cosine_distances.html