mindspore.ops.aminmax
- mindspore.ops.aminmax(input, *, axis=0, keepdims=False)[源代码]
返回tensor在指定轴上的最小值和最大值。
警告
从2.9.0(不含)之后版本开始,该接口将发生非兼容性变更:参数 axis 将重命名为 dim, axis 的默认值将从
0调整为None。- 参数:
input (Tensor) - 输入tensor。
- 关键字参数:
axis (int,可选) - 指定计算的轴。如果为
None,计算 input 中的所有元素。默认0。keepdims (bool,可选) - 输出tensor是否保留维度。默认
False。
- 返回:
由两个tensor组成的tuple(min, max)。
- 支持平台:
AscendGPUCPU
样例:
>>> import mindspore >>> input = mindspore.tensor([[9, 3, 4, 5], ... [5, 2, 7, 4], ... [8, 1, 3, 6]]) >>> >>> # case 1: By default, compute along axis 0. >>> mindspore.ops.aminmax(input) (Tensor(shape=[4], dtype=Int64, value= [5, 1, 3, 4]), Tensor(shape=[4], dtype=Int64, value= [9, 3, 7, 6])) >>> >>> # case 2: Disregard NaN (Not a Number) values present in the input during computation. >>> input = mindspore.tensor([[9, 3, 4, 5], ... [5, 2, 7, 4], ... [8, 1, 3, float('nan')]]) >>> mindspore.ops.aminmax(input, axis=None) (Tensor(shape=[], dtype=Float32, value= 1), Tensor(shape=[], dtype=Float32, value= 9)) >>> >>> # case 3: If keepdims=True, the output shape will be the same as that of the input. >>> mindspore.ops.aminmax(input, axis=None, keepdims=True) (Tensor(shape=[1, 1], dtype=Float32, value= [[ 1.00000000e+00]]), Tensor(shape=[1, 1], dtype=Float32, value= [[ 9.00000000e+00]]))