scanpy.Neighbors.compute_neighbors

scanpy.Neighbors.compute_neighbors#

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

Compute distances and connectivities of neighbors.

Parameters:
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 LayerAcc | MultiAcc | str | None (default: None)

Use the indicated representation: a LayerAcc (e.g. A.X, A.layers[...]) or MultiAcc (e.g. A.obsm[...], A.varm[...]). A str is resolve()d to one of those if scanpy.settings.preset is ScanpyV2Preview, otherwise interpreted as 'X' or a key of .obsm.

If None, the representation is chosen automatically: For .n_vars < N_PCS (default: 50), .X is used, otherwise the PCA representation (.obsm['X_pca'], or .obsm['pca'] if it was computed under ScanpyV2Preview). If it 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 Literal['umap', 'gauss', 'jaccard'] | None (default: 'umap')

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

Return type:

None

Returns:

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