scviva.tools.vision.find_knn#
- scviva.tools.vision.find_knn(data, K, exact=False)[source]#
Find K nearest neighbors for every point in data.
- Parameters:
- data
ndarray Coordinates in the latent space.
- K
int Number of neighbors to return per cell.
- exact
bool If
True, use sklearn’s exact brute-force / kd-tree search (matches R VISION’s RANN output exactly, slower for large datasets). IfFalse(default), usepynndescentwhen available for an approximate O(n log n) search, falling back to sklearn if the package is not installed.
- data
- Return type:
- Returns:
- indicesndarray of shape (n_cells, K)
0-based column indices of the K nearest neighbors for each cell.
- distancesndarray of shape (n_cells, K)
Euclidean distances to each of the K nearest neighbors.