mindspore.ops.min
- mindspore.ops.min(input, axis=None, keepdims=False, *, initial=None, where=None)[源代码]
返回tensor在指定轴上的最小值及其索引。
- 参数:
input (Tensor) - 输入tensor。
axis (int) - 指定计算轴。如果为
None
,计算 input 中的所有元素。默认None
。keepdims (bool) - 输出tensor是否保留维度。默认
False
。
- 关键字参数:
initial (scalar, 可选) - 最小值的初始值。默认
None
。where (Tensor[bool], 可选) - 指定计算最小值的范围,该tensor的shape须可被广播到 input 的shape上。必须指定initial值。默认
None
,表示计算全部元素。
- 返回:
两个tensor组成的tuple(min, min_indices)。
- 支持平台:
Ascend
GPU
CPU
样例:
>>> import mindspore >>> input = mindspore.tensor([[2, 5, 1, 6], ... [3, -7, -2, 4], ... [8, -4, 1, -3]]) >>> # case 1: By default, compute the minimum of all elements. >>> mindspore.ops.min(input) (Tensor(shape=[], dtype=Int64, value= -7), Tensor(shape=[], dtype=Int64, value= 0)) >>> >>> # case 2: Compute minimum along axis 1. >>> mindspore.ops.min(input, axis=1) (Tensor(shape=[3], dtype=Int64, value= [ 1, -7, -4]), Tensor(shape=[3], dtype=Int64, value= [2, 1, 1])) >>> >>> # case 3: If keepdims=True, the output shape will be same of that of the input. >>> mindspore.ops.min(input, axis=1, keepdims=True) (Tensor(shape=[3, 1], dtype=Int64, value= [[ 1], [-7], [-4]]), Tensor(shape=[3, 1], dtype=Int64, value= [[2], [1], [1]])) >>> >>> # case 4: Use "where" to include only specific elements in computing the minimum. >>> where = mindspore.tensor([[1, 0, 1, 0], ... [0, 0, 1, 1], ... [1, 1, 1, 0]], dtype=mindspore.bool_) >>> mindspore.ops.min(input, axis=1, keepdims=True, initial=0, where=where) (Tensor(shape=[3, 1], dtype=Int64, value= [[ 0], [-2], [-4]]), Tensor(shape=[3, 1], dtype=Int64, value= [[0], [2], [1]])) >>> >>> # case 5: The shape of "where" must be broadcast compatible with input. >>> where = mindspore.tensor([[False], ... [False], ... [False]]) >>> mindspore.ops.min(input, axis=0, keepdims=True, initial=0, where=where) (Tensor(shape=[1, 4], dtype=Int64, value= [[0, 0, 0, 0]]), Tensor(shape=[1, 4], dtype=Int64, value= [[0, 0, 0, 0]]))