Neighbors.compute_neighbors(n_neighbors=30, n_pcs=None, *, use_rep=None, knn=True, method='umap', transformer=None, metric='euclidean', metric_kwds=mappingproxy({}), random_state=0)[source]#

Compute distances and connectivities of neighbors.

n_neighbors int (default: 30)

Use this number of nearest neighbors.

n_pcs int | None (default: None)

Use this many PCs. If n_pcs==0 use .X if use_rep is None.

use_rep str | None (default: None)

Use the indicated representation. 'X' or any key for .obsm is valid. If None, the representation is chosen automatically: For .n_vars < N_PCS (default: 50), .X is used, otherwise ‘X_pca’ is used. If ‘X_pca’ is not present, it’s computed with default parameters or n_pcs if present.

knn bool (default: True)

Restrict result to n_neighbors nearest neighbors.

method Optional[Literal['umap', 'gauss']] (default: 'umap')

See scanpy.pp.neighbors(). If None, skip calculating connectivities.

Return type:



Writes sparse graph attributes .distances and, if method is not None, .connectivities.