torch.prod#
- torch.prod(input:Tensor,*,dtype:Optional[_dtype])→Tensor#
Returns the product of all elements in the
inputtensor.- 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 todtypebefore the operationis performed. This is useful for preventing data type overflows. Default: None.
Example:
>>>a=torch.randn(1,3)>>>atensor([[-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
inputtensor in the givendimensiondim.If
keepdimisTrue, the output tensor is of the same sizeasinputexcept in the dimensiondimwhere it is of size 1.Otherwise,dimis squeezed (seetorch.squeeze()), resulting inthe 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 todtypebefore the operationis performed. This is useful for preventing data type overflows. Default: None.
Example:
>>>a=torch.randn(4,2)>>>atensor([[ 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])