torch.aminmax — PyTorch 2.7 documentation (original) (raw)

torch.aminmax(input, *, dim=None, keepdim=False, out=None) -> (Tensor min, Tensor max)

Computes the minimum and maximum values of the input tensor.

Parameters

input (Tensor) – The input tensor

Keyword Arguments

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.

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) t tensor([[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]]))