megengine.functional.max¶
- max(inp, axis=None, keepdims=False)[source]¶
Calculates the maximum of tensor elements over a given axis (or axes).
- Parameters
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
) – ifTrue
, 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 Broadcasting mechanism and rules). Otherwise, ifFalse
, the reduced axes (dimensions) must not be included in the result.
- Return type
- Returns
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 isNaN
(i.e.,NaN
values propagate).Examples
>>> 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)