Skip to content

Instantly share code, notes, and snippets.

@alifarazz
Last active June 3, 2020 18:05
Show Gist options
  • Select an option

  • Save alifarazz/fc8e10f15d2463fdb9b94177bb4007b4 to your computer and use it in GitHub Desktop.

Select an option

Save alifarazz/fc8e10f15d2463fdb9b94177bb4007b4 to your computer and use it in GitHub Desktop.
Get minimum Euclidean distance between points in an XY plane using O(n.lgn).
from scipy import spatial
import numpy as np
pos = np.c_[np.random.rand(100), np.random.rand(100)]
tree = spatial.cKDTree(pos)
dist, ids = tree.query(pos, 2)
print(f'min dist: {np.min(dist[:, 1]): 8f}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment