fn

prod

Tensor
prod(x: Tensor, dim: _int | list[_int] | None = None, keepdim: _bool = False)
source

Compute the product of elements along dim.

The multiplicative analogue of sum. Reducing along dim produces a tensor whose entries equal the product of all values that were collapsed.

Parameters

xTensor
Input tensor.
dimint or list of int= None
Dimension(s) to reduce. None reduces over the whole tensor.
keepdimbool= False
Keep reduced dims with size 1.

Returns

Tensor

Reduced tensor.

Notes

y  =  ixi.y \;=\; \prod_{i} x_i .

For numerical reasons, products of many small values are better computed via exp(sum(log(x))).

Examples

>>> import lucid
>>> x = lucid.tensor([1.0, 2.0, 3.0, 4.0])
>>> lucid.prod(x)
Tensor(24.)