graphclust.graphs.knn_graph#
- graphclust.graphs.knn_graph(X, k=5, metric='euclidean')[source]#
Symmetric \(k\)-nearest-neighbor graph.
Samples \(\mathbf{x}_i\) and \(\mathbf{x}_j\) are linked when one of them is among the \(k\) nearest neighbors of the other (union rule).
Examples
>>> import numpy as np >>> A = knn_graph(np.arange(10.0).reshape(-1, 1), k=1) >>> int(A.nnz // 2) 9