torch.prod¶
-
torch.
prod
(input, *, dtype=None) → Tensor¶ Returns the product of all elements in the
input
tensor.- Parameters
input (Tensor) – the input tensor.
- Keyword Arguments
dtype (
torch.dtype
, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtype
before the operation is performed. This is useful for preventing data type overflows. Default: None.
Example:
>>> a = torch.randn(1, 3) >>> a tensor([[-0.8020, 0.5428, -1.5854]]) >>> torch.prod(a) tensor(0.6902)
-
torch.
prod
(input, dim, keepdim=False, *, dtype=None) → Tensor¶
Returns the product of each row of the
input
tensor in the given dimensiondim
.If
keepdim
isTrue
, the output tensor is of the same size asinput
except in the dimensiondim
where it is of size 1. Otherwise,dim
is squeezed (seetorch.squeeze()
), resulting in the output tensor having 1 fewer dimension thaninput
.- Parameters
- Keyword Arguments
dtype (
torch.dtype
, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtype
before the operation is performed. This is useful for preventing data type overflows. Default: None.
Example:
>>> a = torch.randn(4, 2) >>> a tensor([[ 0.5261, -0.3837], [ 1.1857, -0.2498], [-1.1646, 0.0705], [ 1.1131, -1.0629]]) >>> torch.prod(a, 1) tensor([-0.2018, -0.2962, -0.0821, -1.1831])