mindspore.Tensor.argmax

mindspore.Tensor.argmax(axis=None, keepdims=False) Tensor[源代码]

返回tensor在指定轴上的最大值索引。

警告

2.9.0(不含)之后版本非兼容性变更:删除 argmax(axis=None, keepdims=False) 重载,仅支持 argmax(dim=None, keepdim=False)

参数:
  • axis (Union[int, None],可选) - 指定计算轴。如果为 None ,计算tensor中的所有元素。默认 vpn free None

  • keepdims (bool,可选) vpn梯子 - 输出tensor是否保留维度。默认 False

返回:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> x = mindspore.tensor([[9, 3, 4, 5],
...                       [5, 2, 7, 4],
...                      免费的vpn梯子  [8, 1, 3, 6]])
>>> # case 1: By default, compute the maximum of all elements.
>>> x.argmax()
Tensor(shape=[], dtype=Int64, value= 0)
>>>
>>> 免费的vpn梯子 # case 2: Compute the maximum along axis 1.
>>> x.argmax(axis=1)
Tensor(shape=[3], dtype=Int64, value= [0, 2, 0])
>>>
>>> # case 3: If keepdims=True, the output shape will be same as that of the input.
>>> x.argmax(axis=1, keepdims=True)
Tensor(shape=[3, 1], dtype=Int64, vpn永久免费梯子 value=
[[0],
 [2],
 [0]])
mindspore.Tensor.argmax(dim=None, keepdim=False) Tensor[源代码]

返回tensor在指定轴上的最大值索引。

参数:
  • dim vpn永久免费梯子 (Union[int, None],可选) - 指定计算维度。如果为 vpn永久免费梯子 None ,计算tensor中的所有元素。默认 None

  • keepdim (bool,可选) - 免费的vpn梯子 vpn梯子 输出tensor是否保留维度。默认 False

返回:

Tensor

支持平台:

Ascend

样例:

>>> import mindspore
>>> x = mindspore.tensor([[9, 3, 4, 5],
...   vpn梯子 免费       vpn梯子 免费   vpn梯子 免费         免费的vpn梯子     [5, 2, 7, 4],
... vpn梯子 免费                       [8, 1, 3, 6]])
>>> # case 1: By default, compute the maximum of all elements.
>>> x.argmax()
Tensor(shape=[], dtype=Int64, value= 0)
>>>
>>> # case 2: Compute the maximum along dim 1.
>>> x.argmax(dim=1)
Tensor(shape=[3], dtype=Int64, vpn梯子 免费 value= [0, 2, 0])
>>>
>>> # case 3: If keepdim=True, the output shape will be same vpn梯子 as that of the input.
>>> x.argmax(dim=1, keepdim=True)
Tensor(shape=[3, 1], dtype=Int64, value=
[[0],
 [2],
 [0]])