oneflow.max

oneflow.max(input, dim=None, keepdim=False)

Computes the maximum value of all elements in the input tensor.

Parameters
  • input (oneflow.Tensor) – the Input Tensor

  • dim (int, optional) – the dimension to reduce. Default: None

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

Returns

If dim is None, returns the maximum value of all elements in the input tensor. Otherwise, returns a tuple of Tensor (values, indices), where the values are the maximum value of all elements in the input tensor, the indices are the indices of the elements in the original input tensor.

Return type

Tensor or Tuple(oneflow.Tensor, oneflow.Tensor(dtype=int64))

For example:

>>> import oneflow as flow

>>> input = flow.Tensor([[4, 1, 5], [2, 6, 3]])
>>> flow.max(input)
tensor(6., dtype=oneflow.float32)
>>> result = flow.max(input, dim=1)
>>> result.values
tensor([5., 6.], dtype=oneflow.float32)
>>> result.indices
tensor([2, 1], dtype=oneflow.int64)