Skip to content

Instantly share code, notes, and snippets.

@jenkspt
Last active June 5, 2018 17:40
Show Gist options
  • Save jenkspt/539e8474d46325a7c4f0e408c101f4f3 to your computer and use it in GitHub Desktop.
Save jenkspt/539e8474d46325a7c4f0e408c101f4f3 to your computer and use it in GitHub Desktop.
euclidean distance with numpy broadcasting
import numpy as np
def euclidean(A, B):
return np.sqrt(((np.expand_dims(A, axis=-1) - B.T)**2).sum(axis=1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment