mindspore.mint.amax

查看源文件
mindspore.mint.amax(input, dim=(), keepdim=False)[源代码]

返回tensor在指定维度上的最大值。

警告

这是一个实验性API,后续可能修改或删除。

参数:
  • input (Tensor) - 输入tensor。

  • dim (Union[int, tuple(int), list(int)], 可选) - 指定计算维度。 当 dim() 时,计算 input 中的所有元素。默认 ()

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

返回:

Tensor

支持平台:

Ascend

样例:

>>> import mindspore
>>> import numpy as np
>>> x = mindspore.tensor(np.random.randn(3, 4, 5, 6).astype(np.float32))
>>> output = mindspore.mint.amax(x, dim=1, keepdim=True)
>>> print(output.shape)
(3, 1, 5, 6)
>>> # case 1: Reduce a dimension by the maximum value of all elements in the dimension.
>>> x = mindspore.tensor(np.array([[[1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3]],
... [[4, 4, 4, 4, 4, 4], [5, 5, 5, 5, 5, 5], [6, 6, 6, 6, 6, 6]],
... [[7, 7, 7, 7, 7, 7], [8, 8, 8, 8, 8, 8], [9, 9, 9, 9, 9, 9]]]),
... mindspore.float32)
>>> output = mindspore.mint.amax(x)
>>> print(output)
9.0
>>> print(output.shape)
()
>>> # case 2: Reduce a dimension along axis 0.
>>> output = mindspore.mint.amax(x, dim=0, keepdim=True)
>>> print(output)
[[[7. 7. 7. 7. 7. 7.]
  [8. 8. 8. 8. 8. 8.]
  [9. 9. 9. 9. 9. 9.]]]
>>> # case 3: Reduce a dimension along axis 1.
>>> output = mindspore.mint.amax(x, dim=1, keepdim=True)
>>> print(output)
[[[3. 3. 3. 3. 3. 3.]]

 [[6. 6. 6. 6. 6. 6.]]

 [[9. 9. 9. 9. 9. 9.]]]
>>> # case 4: Reduce a dimension along axis 2.
>>> output = mindspore.mint.amax(x, dim=2, keepdim=True)
>>> print(output)
[[[1.]
  [2.]
  [3.]]

 [[4.]
  [5.]
  [6.]]

 [[7.]
  [8.]
  [9.]]]