scanpy.pp.downsample_counts#
- scanpy.pp.downsample_counts(adata, counts_per_cell=None, total_counts=None, *, rng=None, replace=False, copy=False)[source]#
Downsample counts from count matrix.
If
counts_per_cellis specified, each cell will downsampled. Iftotal_countsis specified, expression matrix will be downsampled to contain at mosttotal_counts.Array type support# Array type
supported
… experimentally in dask
Array✅
❌
✅
❌
❌
❌
- Parameters:
- adata
AnnData Annotated data matrix.
- counts_per_cell
int|Collection[int] |None(default:None) Target total counts per cell. If a cell has more than ‘counts_per_cell’, it will be downsampled to this number. Resulting counts can be specified on a per cell basis by passing an array.Should be an integer or integer ndarray with same length as number of obs.
- total_counts
int|None(default:None) Target total counts. If the count matrix has more than
total_countsit will be downsampled to have this number.- rng
int|integer|Sequence[int] |SeedSequence|Generator|BitGenerator|None(default:None) Random number generation to control stochasticity.
If a type:
SeedLikevalue, it’s used to seed a new random number generator; If anumpy.random.Generator,rng’s state will be directly advanced; IfNone, a non-reproducible random number generator is used. Seenumpy.random.default_rng()for more details.The default value matches legacy scanpy behavior and will change to
Nonein scanpy 2.0.- replace
bool(default:False) Whether to sample the counts with replacement.
- copy
bool(default:False) Determines whether a copy of
adatais returned.
- adata
- Return type:
- Returns:
Returns
Noneifcopy=False, else returns anAnnDataobject. Sets the following fields:adata.Xndarray|csr_matrix|csc_matrix(dtypefloat)Downsampled counts matrix.