Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from sklearn.neighbors import KDTree
- rng = np.random.RandomState(0)
- Y = rng.random_sample((5, 3))
- # ~ blob_num = np.loadtxt("blobNumber.txt")
- global X
- file1 = open("blobNumber.txt","r")
- blob_num_1 = file1.read()
- word = blob_num_1.split()
- blob_num = int(word[0])
- print blob_num
- file1.close()
- X = np.zeros((blob_num,3),dtype=float)
- data = np.loadtxt("blobCoordinates.txt")
- x = data[:,0]
- y = data[:,1]
- z = data[:,2]
- for i in range(np.size(x)):
- X[i][0] = x[i]
- X[i][1] = y[i]
- X[i][2] = z[i]
- print X[[10]]
- tree = KDTree(X, leaf_size=2)
- file1 = open("neighbourList.txt","w")#write mode
- for i in range(np.size(x)):
- dist, ind = tree.query(X[[i]], k=2)
- print(ind) # indices of 3 closest neighbors
- file1.write(ind)
- file1.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement