Created
October 28, 2019 16:30
-
-
Save rileypeterson/0e787926572e59fa982d3263c14a5fbd to your computer and use it in GitHub Desktop.
KD Tree Demo
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
from scipy.spatial import cKDTree | |
import time | |
import numpy as np | |
np.random.seed(42) | |
st = time.time() | |
a = np.random.rand(40000, 25) | |
b = np.random.rand(40000, 25) | |
t0 = cKDTree(a) | |
t1 = cKDTree(b) | |
# res = np.empty((len(b), 10)) | |
for i in range(0, len(b), 5000): | |
print(i) | |
dists0, inds0 = t0.query(b[i:i+5000], k=1000, n_jobs=-1) | |
dists1, inds1 = t1.query(a[i:i+5000], k=1000, n_jobs=-1) | |
# res[i:i+1000] = t0.query(b[i:i+1000], k=10, n_jobs=-1)[1] | |
# res = np.vstack((res, t0.query(b[i:i+1000], k=10, n_jobs=-1)[1])) | |
print(time.time() - st) |
Author
rileypeterson
commented
Nov 5, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment