prod(input, dim=None, keepdim=False) → Tensor¶
Computes the product of row of elements in a tensor in the given dimension. If the dimension is None, product of all elements will be caculated.
If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed
oneflow.squeeze(), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s).
input (oneflow.Tensor) – the Input Tensor
dim (int or tuple of ints, optional) – the dimension to reduce. Default: None
keepdim (bool, optional) – whether the output tensor has dim retained or not. Default: False
>>> import oneflow as flow >>> input = flow.Tensor([[1, 2, 3], [4, 5, 6]]) >>> flow.prod(input) tensor(720., dtype=oneflow.float32) >>> flow.prod(input, dim=0) tensor([ 4., 10., 18.], dtype=oneflow.float32) >>> flow.prod(input, dim=1) tensor([ 6., 120.], dtype=oneflow.float32)