Skip to content

Instantly share code, notes, and snippets.

@hyponymous
Created November 30, 2018 20:45
Show Gist options
  • Save hyponymous/a7970b77bd5daf6ec6dfd14aba039a89 to your computer and use it in GitHub Desktop.
Save hyponymous/a7970b77bd5daf6ec6dfd14aba039a89 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import itertools
import numpy as np
N = 1000
d = 500
x_normal = np.random.multivariate_normal([0], [[1]], [N, d]).reshape([N, d])
x_spherical = x_normal / np.linalg.norm(x_normal, axis=1)[:, np.newaxis]
idx_pairs = itertools.product(range(N), range(N))
best = min([np.linalg.norm(x_spherical[i] - x_spherical[j]) for i, j in idx_pairs if i != j])
print('Distance of closest pair among {} points (dim = {}): {}'.format(N, d, best))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment