scanpy.pp.sample

Contents

scanpy.pp.sample#

scanpy.pp.sample(data, fraction=None, *, n=None, rng=None, copy=False, replace=False, axis='obs', p=None)[source]#
Overloads:
  • data (AnnData), fraction (float | None), n (int | None), rng (RNGLike | SeedLike | None), copy (Literal[False]), replace (bool), axis (Literal[‘obs’, 0, ‘var’, 1]), p (str | NDArray[np.bool] | NDArray[np.floating] | None) → None

  • data (AnnData), fraction (float | None), n (int | None), rng (RNGLike | SeedLike | None), copy (Literal[True]), replace (bool), axis (Literal[‘obs’, 0, ‘var’, 1]), p (str | NDArray[np.bool] | NDArray[np.floating] | None) → AnnData

  • data (A), fraction (float | None), n (int | None), rng (RNGLike | SeedLike | None), copy (bool), replace (bool), axis (Literal[‘obs’, 0, ‘var’, 1]), p (str | NDArray[np.bool] | NDArray[np.floating] | None) → tuple[A, NDArray[np.int64]]

Sample observations or variables with or without replacement.

Array type support#

Array type

supported

… experimentally in dask Array

numpy.ndarray

scipy.sparse.{csr,csc}_{array,matrix}

Parameters:
data AnnData | ndarray | csr_array | csc_array | 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 are 0s/Falses in p.) This can be larger than 1.0, if replace=True. See axis and replace.

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 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 observations (axis 0) or variables (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. If p is an array of probabilities, it must sum to 1.

Returns:

If isinstance(data, AnnData) and copy=False, this function returns None. Otherwise:

data[indices, :] | data[:, indices] (depending on axis)

If data is array-like or copy=True, returns the subset.

indicesnumpy.ndarray

If data is array-like, also returns the indices into the original.