torch.aminmax
- torch.aminmax(input, *, dim=None, keepdim=False, out=None) -> (Tensor min, Tensor max)
Computes the minimum and maximum values of the
inputtensor.- Parameters
Computes the minimum and maximum values of the input tensor.
input (Tensor) – The input tensor
dim (Optional[int]) – The dimension along which to compute the values. If None,
computes the values over the entire input tensor.
Default is None.
keepdim (bool) – If True, the reduced dimensions will be kept in the output
tensor as dimensions with size 1 for broadcasting, otherwise
they will be removed, as if calling (torch.squeeze()).
Default is False.
out (Optional[Tuple[Tensor, Tensor]]) – Optional tensors on which to write the result. Must have the same shape and dtype as the expected output. Default is None.
A named tuple (min, max) containing the minimum and maximum values.
RuntimeError – If any of the dimensions to compute the values over has size 0.
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]]))