max(inp, axis=None, keepdims=False)[源代码]

Calculates the maximum of tensor elements over a given axis (or axes).

  • inp (Tensor) – input tensor. Should have a numeric data type.

  • axis (Union[int, Sequence[int], None]) – axis or axes along which maximums must be computed. By default, the maximum must be computed over the entire tensor. If a sequence of integers, maximums must be computed over multiple axes.

  • keepdims (bool) – if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input tensor (see 广播机制与规则). Otherwise, if False, the reduced axes (dimensions) must not be included in the result.




if the maximum was computed over the entire tensor, a zero-dimensional tensor containing the maximum; otherwise, a non-zero-dimensional tensor containing the maximums.

Special Cases

If \(x_i\) is NaN, the maximum is NaN (i.e., NaN values propagate).


>>> x = Tensor([[1, 2], [3, 4]])
>>> F.max(x)
Tensor(4, dtype=int32, device=xpux:0)

Along an axis:

>>> F.max(x, axis=0)
Tensor([3 4], dtype=int32, device=xpux:0)
>>> F.max(x, axis=1)
Tensor([2 4], dtype=int32, device=xpux:0)