Last active
April 6, 2016 18:41
-
-
Save pinkwerks/9969927 to your computer and use it in GitHub Desktop.
Nearest neigbor from a point in 3d space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# find nearest neighbor of a point | |
import numpy as np | |
from scipy import spatial | |
# create 10 random points | |
x, y, z = np.random.rand(3,10) | |
# format our points for the kdtree function | |
points = [i for i in zip(x,y,z)] | |
# make the kdtree with the points | |
tree = spatial.KDTree(points) | |
# create a query point | |
qpoint = np.array([0,0,0]) | |
# make the query, returns distance to point and the index in 'points' | |
tree.query(qpoint) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment