def clusters(points, radius):
'''
Find clusters of points which have neighbours closer than radius
Arguments
---------
points: (n, d) points (of dimension d)
radius: max distance between points in a cluster
Returns:
groups: (m) sequence of indices for points
'''
tree = KDTree(points)
pairs = tree.query_pairs(radius)
graph = from_edgelist(pairs)
groups = list(connected_components(graph))
return groups
评论列表
文章目录