mindspore.Tensor.argmin_with_value
- mindspore.Tensor.argmin_with_value(axis=0, keep_dims=False)[源代码]
返回tensor在指定轴上的最小值及其索引。
- 参数:
axis (Union[int, None], 可选) - 指定计算轴。如果为
None
,计算tensor中的所有元素。默认0
。keep_dims (bool, 可选) - 输出tensor是否保留维度。默认
False
。
- 返回:
两个tensor组成的tuple(min, min_indices)。
- 支持平台:
Ascend
GPU
CPU
样例:
>>> import mindspore >>> x = mindspore.tensor([[2, 5, 1, 6], ... [3, -7, -2, 4], ... [8, -4, 1, -3]]) >>> # case 1: By default, compute the minimum along axis 0. >>> x.argmin_with_value() (Tensor(shape=[4], dtype=Int64, value= [ 2, -7, -2, -3]), Tensor(shape=[4], dtype=Int64, value= [0, 1, 1, 2])) >>> >>> # case 2: Compute the minimum along axis 1. >>> x.argmin_with_value(axis=1) (Tensor(shape=[3], dtype=Int64, value= [ 1, -7, -4]), Tensor(shape=[3], dtype=Int64, value= [2, 1, 1])) >>> >>> # case 3: If keep_dims=True, the output shape will be same of that of the input. >>> x.argmin_with_value(axis=1, keep_dims=True) (Tensor(shape=[3, 1], dtype=Int64, value= [[ 1], [-7], [-4]]), Tensor(shape=[3, 1], dtype=Int64, value= [[2], [1], [1]])) >>> >>> # case 4: If axis=None, compute the minimum of all elements. >>> x.argmin_with_value(axis=None, keep_dims=True) (Tensor(shape=[], dtype=Int64, value= -7), Tensor(shape=[], dtype=Int64, value= 0))