megengine.functional.max¶
- 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
) – 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 广播机制与规则). Otherwise, ifFalse
, 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 isNaN
(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)