snapatac2.pp.knn#
- snapatac2.pp.knn(adata, n_neighbors=50, use_dims=None, use_rep='X_spectral', method='hora', n_jobs=-1, inplace=True, random_state=0)[source]#
Compute a neighborhood graph of observations.
Computes a neighborhood graph of observations stored in
adatausing the method specified bymethod. The distance metric used is Euclidean.- Parameters:
adata (
AnnData|AnnDataSet|ndarray) – Annotated data matrix or numpy array.n_neighbors (
int) – The number of nearest neighbors to be searched.use_dims (
Union[int,list[int],None]) – The dimensions used for computation.use_rep (
str) – The key for the matrixmethod (
Literal['hora','pynndescent','exact']) – ‘hora’, ‘pynndescent’, or ‘exact’. The default is ‘hora’, which uses the HNSW algorithm to approximate the nearest neighbors.n_jobs (
int) – number of CPUs to useinplace (
bool) – Whether to store the result in the anndata object.random_state (
int) – Random seed for approximate nearest neighbor search.
- Returns:
if
inplace=True, store KNN in.obsp['distances']. Otherwise, return a sparse matrix.- Return type:
csr_matrix | None