Skip to content

Easy euclidean distance #159

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

yupbank
Copy link
Contributor

@yupbank yupbank commented Nov 2, 2018

In [1]: import numpy as np

In [2]: from sklearn.metrics import pairwise_distances

In [3]: a = np.random.randn(10, 7)

In [4]: b = np.random.randn(5, 7)

In [5]: np.allclose(np.sqrt(np.linalg.norm(a, axis=1, keepdims=True)**2 
                                           - 2*np.matmul(a, b.T) 
                                           + np.linalg.norm(b, axis=1, keepdims=True).T**2),
                              pairwise_distances(a, b))
Out[5]: True

In [6]:

@yupbank
Copy link
Contributor Author

yupbank commented Nov 2, 2018

@tjhunter

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant