mindspore.Tensor.argmax_with_value
- Tensor.argmax_with_value(axis=0, keep_dims=False)[source]
Return the maximum values and their indices along the given axis of the tensor.
- Parameters
- Returns
Tuple(max, max_indices) of 2 tensors.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> x = mindspore.tensor([[9, 3, 4, 5], ... [5, 2, 7, 4], ... [8, 1, 3, 6]]) >>> # case 1: By default, compute the maximum along axis 0. >>> x.argmax_with_value() (Tensor(shape=[4], dtype=Int64, value= [9, 3, 7, 6]), Tensor(shape=[4], dtype=Int64, value= [0, 0, 1, 2])) >>> >>> # case 2: Compute the maximum along axis 1. >>> x.argmax_with_value(axis=1) (Tensor(shape=[3], dtype=Int64, value= [9, 7, 8]), Tensor(shape=[3], dtype=Int64, value= [0, 2, 0])) >>> >>> # case 3: If keep_dims=True, the output shape will be same of that of the input. >>> x.argmax_with_value(axis=1, keep_dims=True) (Tensor(shape=[3, 1], dtype=Int64, value= [[9], [7], [8]]), Tensor(shape=[3, 1], dtype=Int64, value= [[0], [2], [0]])) >>> >>> # case 4: If axis=None, compute the maximum of all elements. >>> x.argmax_with_value(axis=1, keep_dims=True) (Tensor(shape=[], dtype=Int64, value= 9), Tensor(shape=[], dtype=Int64, value= 0))