Skip to content
fn

mean

→Tensor
mean(input: Tensor, dim: _int | list[_int] | None = None, keepdim: _bool = False, dtype: DTypeLike = None)

Implementing kernel

C++ engine symbols that back this Python API.

Compute the arithmetic mean along dim.

The sample mean of n values is

xˉ  =  1n∑i=1nxi.\bar{x} \;=\; \frac{1}{n} \sum_{i=1}^{n} x_i .

Floating-point results are accumulated in the same dtype as the input; integer inputs are promoted to the default floating dtype before the reduction is performed.

Parameters

inputTensor
Input tensor.
dimint or list of int= None
Dimension(s) to reduce. None reduces over all elements.
keepdimbool= False
Whether to retain the reduced dim(s) with size 1.

Returns

Tensor

Reduced tensor of floating dtype.

Notes

Mean is an unbiased estimator of the population mean. For empty reductions (size-0 dim) the result is nan.

Examples

>>> import lucid
>>> x = lucid.tensor([[1.0, 2.0], [3.0, 4.0]])
>>> lucid.mean(x)
Tensor(2.5)
>>> lucid.mean(x, dim=0)
Tensor([2., 3.])