Rate this Page

torch.aminmax#

torch.aminmax(input,*,dim=None,keepdim=False,out=None)->(Tensormin,Tensormax)#

Computes the minimum and maximum values of theinput tensor.

Parameters

input (Tensor) – The input tensor

Keyword Arguments
  • dim (Optional[int]) – The dimension along which to compute the values. IfNone,computes the values over the entireinput tensor.Default isNone.

  • keepdim (bool) – IfTrue, the reduced dimensions will be kept in the outputtensor as dimensions with size 1 for broadcasting, otherwisethey will be removed, as if calling (torch.squeeze()).Default isFalse.

  • out (Optional[Tuple[Tensor,Tensor]]) – Optional tensors on which to write the result. Must have the sameshape and dtype as the expected output.Default isNone.

Returns

A named tuple(min, max) containing the minimum and maximum values.

Raises

RuntimeError – If any of the dimensions to compute the values over has size 0.

Note

NaN values are propagated to the output if at least one value is NaN.

See also

torch.amin() computes just the minimum valuetorch.amax() computes just the maximum value

Example:

>>>torch.aminmax(torch.tensor([1,-3,5]))torch.return_types.aminmax(min=tensor(-3),max=tensor(5))>>># aminmax propagates NaNs>>>torch.aminmax(torch.tensor([1,-3,5,torch.nan]))torch.return_types.aminmax(min=tensor(nan),max=tensor(nan))>>>t=torch.arange(10).view(2,5)>>>ttensor([[0, 1, 2, 3, 4],        [5, 6, 7, 8, 9]])>>>t.aminmax(dim=0,keepdim=True)torch.return_types.aminmax(min=tensor([[0, 1, 2, 3, 4]]),max=tensor([[5, 6, 7, 8, 9]]))