I have a few points and like to determine if they are in a specific distance to each other. If they are, I want to merge them into one point. I build a search tree and got a distance matrix from it. Is there an elegant (without slow loops if possible) way to determine which points are in specific distance without using some complex cluster algorithm (kmeans, hierarchical, etc.)?
import numpy as np
from sklearn.neighbors import NearestNeighbors
from sklearn.neighbors import radius_neighbors_graph
RADIUS = 0.025
points = np.array([
[13.2043373032, 52.3818529896],
[13.0530692845, 52.3991668707],
[13.229309674, 52.3840231],
[13.489018081, 52.4180538095],
[13.3209738098, 52.6375963146],
[13.0160362703, 52.4187139243],
[13.0448485, 52.4143229343],
[13.32478977, 52.5090253],
[13.35514839, 52.5219323867],
[13.1982523828, 52.3592620828]
])
tree = NearestNeighbors(n_neighbors=2, radius=RADIUS, leaf_size=30, algorithm="auto", n_jobs=1).fit(points)
nnGraph = radius_neighbors_graph(tree, RADIUS, mode='distance', include_self=False)
print nnGraph
(0, 9) 0.0233960536484
(1, 6) 0.0172420289306
(6, 1) 0.0172420289306
(9, 0) 0.0233960536484