mindspore.ops.aminmax
- mindspore.ops.aminmax(input, *, axis=0, keepdims=False)[源代码]
返回tensor在指定轴上的最小值和最大值。
- 参数:
input (Tensor) - 输入tensor。
- 关键字参数:
axis (int,可选) - 指定计算的轴。如果为
None
,计算 input 中的所有元素。默认0
。keepdims (bool,可选) - 输出tensor是否保留维度。默认
False
。
- 返回:
两个tensor组成的tuple(min, max)。
- 支持平台:
Ascend
GPU
CPU
样例:
>>> 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 same of 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]]))