max( x, axis=None, keepdim=False, name=None )
Computes the maximum of tensor elements over the given axis.
x (Tensor) – A tensor, the data type is float32, float64, int32, int64.
axis (list|int, optional) – The axis along which the maximum is computed. If
None, compute the maximum over all elements of x and return a Tensor with a single element, otherwise must be in the range \([-x.ndim(x), x.ndim(x))\). If \(axis[i] < 0\), the axis to reduce is \(x.ndim + axis[i]\).
keepdim (bool, optional) – Whether to reserve the reduced dimension in the output Tensor. The result tensor will have one fewer dimension than the x unless
keepdimis true, default value is False.
name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name
Tensor, results of maximum on the specified axis of input tensor, it’s data type is the same as x.
import paddle # data_x is a Tensor with shape [2, 4] # the axis is a int element x = paddle.to_tensor([[0.2, 0.3, 0.5, 0.9], [0.1, 0.2, 0.6, 0.7]]) result1 = paddle.max(x) print(result1) #[0.9] result2 = paddle.max(x, axis=0) print(result2) #[0.2 0.3 0.6 0.9] result3 = paddle.max(x, axis=-1) print(result3) #[0.9 0.7] result4 = paddle.max(x, axis=1, keepdim=True) print(result4) #[[0.9] # [0.7]] # data_y is a Tensor with shape [2, 2, 2] # the axis is list y = paddle.to_tensor([[[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]]]) result5 = paddle.max(y, axis=[1, 2]) print(result5) #[4. 8.] result6 = paddle.max(y, axis=[0, 1]) print(result6) #[7. 8.]