mindspore.ops.amax
- mindspore.ops.amax(input, axis=None, keepdims=False, *, initial=None, where=None)[source]
Return the maximum values along the given axis of the tensor.
- Parameters
- Keyword Arguments
initial (scalar, optional) – Initial value for the maximum. Default
None
.where (Tensor[bool], optional) – Specifies the range over which to compute the maximum values. The shape of this tensor must be broadcastable to the shape of input . An initial value must be specified. Default
None
, indicating that all elements are to be computed.
- Returns
Tensor
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> input = mindspore.tensor([[9, 3, 4, 5], ... [5, 2, 7, 4], ... [8, 1, 3, 6]]) >>> # case 1: By default, compute the maximum of all elements. >>> mindspore.ops.amax(input) Tensor(shape=[], dtype=Int64, value= 9) >>> >>> # case 2: Compute maximum along axis 1. >>> mindspore.ops.amax(input, axis=1) Tensor(shape=[3], dtype=Int64, value= [9, 7, 8]) >>> >>> # case 3: If keepdims=True, the output shape will be same of that of the input. >>> mindspore.ops.amax(input, axis=1, keepdims=True) Tensor(shape=[3, 1], dtype=Int64, value= [[9], [7], [8]]) >>> >>> # case 4: Use "where" to include only specific elements in computing the maximum. >>> where = mindspore.tensor([[0, 0, 1, 0], ... [0, 0, 1, 1], ... [1, 1, 1, 0]], dtype=mindspore.bool_) >>> mindspore.ops.amax(input, axis=1, keepdims=True, initial=0, where=where) Tensor(shape=[3, 1], dtype=Int64, value= [[4], [7], [8]]) >>> >>> # case 5: The shape of "where" must be broadcast compatible with input. >>> where = mindspore.tensor([[False], ... [False], ... [False]]) >>> mindspore.ops.amax(input, axis=0, keepdims=True, initial=0, where=where) Tensor(shape=[1, 4], dtype=Int64, value= [[0, 0, 0, 0]])