scviva.tools.vision.find_knn

Contents

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 of shape (n_cells, n_dims)) – Coordinates in the latent space.

  • K (int) – Number of neighbors to return per cell.

  • exact (bool, optional) – If True, use sklearn’s exact brute-force / kd-tree search (matches R VISION’s RANN output exactly, slower for large datasets). If False (default), use pynndescent when available for an approximate O(n log n) search, falling back to sklearn if the package is not installed.

Return type:

tuple[ndarray, ndarray]

Returns:

  • indices (ndarray of shape (n_cells, K)) – 0-based column indices of the K nearest neighbors for each cell.

  • distances (ndarray of shape (n_cells, K)) – Euclidean distances to each of the K nearest neighbors.