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

Returns the minimum value of each slice of the input tensor in the given dimension(s) dim.


The difference between max/min and amax/amin is:
  • amax/amin supports reducing on multiple dimensions,

  • amax/amin does not return indices,

  • amax/amin evenly distributes gradient between equal values, while max(dim)/min(dim) propagates gradient only to a single index in the source tensor.

If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s).

  • input (Tensor) – the input tensor.

  • dim (int or tuple of ints) – the dimension or dimensions to reduce.

  • keepdim (bool) – whether the output tensor has dim retained or not.

Keyword Arguments

out (Tensor, optional) – the output tensor.


>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.6451, -0.4866,  0.2987, -1.3312],
        [-0.5744,  1.2980,  1.8397, -0.2713],
        [ 0.9128,  0.9214, -1.7268, -0.2995],
        [ 0.9023,  0.4853,  0.9075, -1.6165]])
>>> torch.amin(a, 1)
tensor([-1.3312, -0.5744, -1.7268, -1.6165])


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources