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
fraction
of the number of observations or variables. (All of them, even if there are0`s/`False`s in `p
.) This can be larger than 1.0, ifreplace=True
. Seeaxis
andreplace
.- n
int
|None
(default:None
) Sample to this number of observations or variables. See
axis
.- random_state
Random seed to change subsampling.
- copy
bool
(default:False
) If an
AnnData
is 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
obs
ervations (axis 0) orvar
iables (axis 1).- p
str
|ndarray
[Any
,dtype
[bool
]] |ndarray
[Any
,dtype
[floating
]] |None
(default:None
) Drawing probabilities (floats) or mask (bools). Either an
axis
-sized array, or the name of a column. Ifp
is an array of probabilities, it must sum to 1.
- data
- Return type:
AnnData
|None
|tuple
[ndarray
|csr_matrix
|csc_matrix
|Array
,ndarray
[Any
,dtype
[int64
]]]- Returns:
If
isinstance(data, AnnData)
andcopy=False
, this function returnsNone
. Otherwise:data[indices, :]
|data[:, indices]
(depending onaxis
)If
data
is array-like orcopy=True
, returns the subset.indices
numpy.ndarrayIf
data
is array-like, also returns the indices into the original.