Rate this Page

torch.prod#

torch.prod(input:Tensor,*,dtype:Optional[_dtype])Tensor#

Returns the product of all elements in theinput 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 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 theinput tensor in the givendimensiondim.

Ifkeepdim isTrue, the output tensor is of the same sizeasinput except in the dimensiondim where it is of size 1.Otherwise,dim is squeezed (seetorch.squeeze()), resulting inthe output tensor having 1 fewer dimension thaninput.

Parameters
  • input (Tensor) – the input tensor.

  • dim (int,optional) – the dimension to reduce.IfNone, all dimensions are reduced.

  • keepdim (bool,optional) – whether the output tensor hasdim retained or not. Default:False.

Keyword Arguments

dtype (torch.dtype, optional) – the desired data type of returned tensor.If specified, the input tensor is casted todtype before 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])