fn
reduce
→Tensorreduce(tensor: Tensor, pattern: str, reduction: str, axes_lengths: int = {})Reduce tensor along axes implied by an einops pattern.
Generalises standard sum / mean / max / min /
prod reductions to arbitrary axes selected by symbolic pattern.
Any axis present on the left-hand side of -> but absent on the
right-hand side is collapsed by the chosen reduction.
Parameters
tensorTensorInput tensor to reduce.
patternstrEinops pattern such as
"b h w -> b w".reductionstrReduction operation; one of
"sum", "mean", "max",
"min", "prod".**axes_lengthsint= {}Named axis sizes used to disambiguate decomposed groups.
Returns
TensorThe reduced tensor.
Notes
Conceptually equivalent to a permutation followed by a reduction
along contiguous trailing axes. For reduction="mean" the result
is
Examples
>>> import lucid
>>> x = lucid.randn(2, 3, 4)
>>> lucid.einops.reduce(x, "b h w -> b w", "mean").shape
(2, 4)