Rate this Page

torch.amax#

torch.amax(input,dim,keepdim=False,*,out=None)Tensor#

Returns the maximum value of each slice of theinput tensor in the givendimension(s)dim.

Note

The difference betweenmax/min andamax/amin is:
  • amax/amin supports reducing on multiple dimensions,

  • amax/amin does not return indices.

Bothamax/amin evenly distribute gradients between equal valueswhen there are multiple input elements with the same minimum or maximum value.

Formax/min:
  • If reduce over all dimensions(no dim specified), gradients evenly distribute between equallymax/min values.

  • If reduce over one specified axis, only propagate to the indexed element.

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

Parameters
  • input (Tensor) – the input tensor.

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

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

Keyword Arguments

out (Tensor,optional) – the output tensor.

Example:

>>>a=torch.randn(4,4)>>>atensor([[ 0.8177,  1.4878, -0.2491,  0.9130],        [-0.7158,  1.1775,  2.0992,  0.4817],        [-0.0053,  0.0164, -1.3738, -0.0507],        [ 1.9700,  1.1106, -1.0318, -1.0816]])>>>torch.amax(a,1)tensor([1.4878, 2.0992, 0.0164, 1.9700])