anndata.AnnData.reduce#
- AnnData.reduce(func, *, init, order='DFS-post')[source]#
Accumulate a value starting from init by iterating over the “elems”/leaf nodes of the AnnData object.
All visits inside the user-defined
func(seetypes.ReduceFunc()) are distinguishable via theref_acc+elemargs. Visits to {attr}`~AnnData.raw` passref_acc is Noneandisinstance(elem, Raw)to thetypes.ReduceFunc(). Visits to {attr}`~AnnData.uns` passref_acc is Noneandisinstance(elem, dict)to thetypes.ReduceFunc(). Furthermore, neither element is descended into. This behavior could change where a newref_acctype will be available, in which case we could start descending in these cases. All other elements will have a non-Noneref_accargument indicating the path at whichelemwas created in theAnnData.- Parameters:
- func
ReduceFunc[TypeVar(T)] The function that performs the accumulation.
- init
TypeVar(T) The starting value
- order
Literal['DFS-pre','DFS-post'] (default:'DFS-post') How to visit the items in the reduce. “DFS-pre” indicates that parent-elements like layers, obs, and varp get visited first. “DFS-post” means they get visited afterwards. The
AnnDataitself is not visited.
- func
- Return type:
TypeVar(T)- Returns:
An accumulated value