mindspore.Tensor.argmax
- Tensor.argmax(axis=None, keepdims=False) Tensor
Return the indices of the maximum values of a tensor across a dimension.
- Parameters
axis (Union[int, None], optional) – The dimension to reduce. If axis is
None
, the indices of the maximum value within the flattened input will be returned. The value of axis cannot exceed the dimension of self. Default:None
.keepdims (bool, optional) – Whether the output tensor retains the specified dimension. Ignored if dim is None. Default:
False
.
- Returns
Tensor, indices of the maximum values across a dimension.
- Raises
TypeError – If keepdims is not bool.
ValueError – If axis is out of range.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import Tensor >>> x = Tensor(np.array([[1, 20, 5], [67, 8, 9], [130, 24, 15]]).astype(np.float32)) >>> output = Tensor.argmax(x, axis=-1) # x.argmax(axis=-1) >>> print(output) [1 0 0]
- Parameters
dim (Union[int, None], optional) – The dimension to reduce. If axis is
None
, the indices of the maximum value within the flattened input will be returned. The value of axis cannot exceed the dimension of self. Default:None
.keepdim (bool, optional) – Whether the output tensor retains the specified dimension. Ignored if dim is None. Default:
False
.
- Returns
Tensor, indices of the maximum values across a dimension.
- Raises
TypeError – If keepdim is not bool.
ValueError – If dim is out of range.
- Supported Platforms:
Ascend
Examples
>>> import numpy as np >>> from mindspore import Tensor >>> x = Tensor(np.array([[1, 20, 5], [67, 8, 9], [130, 24, 15]]).astype(np.float32)) >>> output = Tensor.argmax(x, dim=-1) # x.argmax(dim=-1) >>> print(output) [1 0 0]