multidim.PointCloud.nearest_neighbors

PointCloud.nearest_neighbors(k)[source]

Compute k nearest-neighbors of the PointCloud, using a clever CoverTree algorithm. Answers are cached in self._nn[k]

Parameters:
k: int

How many nearest neighbors to compute

Returns:
np array with dtype int and shape==(N,k+1). Entry [i,j] is the jth
nearest neighbor of vertex i. Note that entry [i,0] == i, so [i,k]
is the kth nearest neighbor.

Examples

>>> pc = PointCloud(np.array([[ 0.58814682,  0.45405299],
...                           [ 0.09197879,  0.39721367],
...                           [ 0.29128654,  0.28372039],
...                           [ 0.14593167,  0.7027367 ],
...                           [ 0.77068438,  0.37849037],
...                           [ 0.17281855,  0.70204687],
...                           [ 0.48146217,  0.54619034],
...                           [ 0.27831744,  0.67327757],
...                           [ 0.49074255,  0.70847318],
...                           [ 0.132656,    0.0860524 ]]))
>>> pc.nearest_neighbors(3)
array([[0, 6, 4, 8],
       [1, 2, 3, 9],
       [2, 1, 9, 6],
       [3, 5, 7, 1],
       [4, 0, 6, 8],
       [5, 3, 7, 1],
       [6, 0, 8, 7],
       [7, 5, 3, 8],
       [8, 6, 7, 0],
       [9, 2, 1, 6]])