Skip to content

Instantly share code, notes, and snippets.

@dboyliao
Last active May 3, 2020 09:04
Show Gist options
  • Save dboyliao/6a6fa5f3d547df60f13ed445f7b09a29 to your computer and use it in GitHub Desktop.
Save dboyliao/6a6fa5f3d547df60f13ed445f7b09a29 to your computer and use it in GitHub Desktop.
import numpy as np
from itertools import combinations
def distance_loop(X):
N, M = X.shape
dist = np.zeros((N, N))
for i, j in combinations(range(N), 2):
xi = X[i]
xj = X[j]
dist[i, j] = dist[j, i] = ((xi - xj) ** 2).sum()
return dist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment