scanpy.pp.sample#
- scanpy.pp.sample(data, fraction=None, *, n=None, rng=None, copy=False, replace=False, axis='obs', p=None)[source]#
 Sample observations or variables with or without replacement.
- Parameters:
 - data 
AnnData|ndarray|csr_matrix|csc_matrix|Array The (annotated) data matrix of shape
n_obs×n_vars. Rows correspond to cells and columns to genes.- fraction 
float|None(default:None) Sample to this
fractionof the number of observations or variables. (All of them, even if there are0s/Falses inp.) This can be larger than 1.0, ifreplace=True. Seeaxisandreplace.- n 
int|None(default:None) Sample to this number of observations or variables. See
axis.- rng 
Generator|BitGenerator|int|integer|Sequence[int] |SeedSequence|None(default:None) Random seed to change subsampling.
- copy 
bool(default:False) If an
AnnDatais passed, determines whether a copy is returned.- replace 
bool(default:False) If True, samples are drawn with replacement.
- axis 
Literal['obs',0,'var',1] (default:'obs') Sample
observations (axis 0) orvariables (axis 1).- p 
str|ndarray[tuple[Any,...],dtype[bool]] |ndarray[tuple[Any,...],dtype[floating]] |None(default:None) Drawing probabilities (floats) or mask (bools). Either an
axis-sized array, or the name of a column. Ifpis an array of probabilities, it must sum to 1.
- data 
 - Return type:
 AnnData|None|tuple[ndarray|csr_matrix|csc_matrix|Array,ndarray[tuple[Any,...],dtype[int64]]]- Returns:
 If
isinstance(data, AnnData)andcopy=False, this function returnsNone. Otherwise:data[indices, :]|data[:, indices](depending onaxis)If
datais array-like orcopy=True, returns the subset.indicesnumpy.ndarrayIf
datais array-like, also returns the indices into the original.