Skip to content

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

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

Successfully merging this pull request may close these issues.

1 participant