mindspore.Tensor.argmin_with_value

View Source On Gitee
Tensor.argmin_with_value(axis=0, keep_dims=False)[source]

Return the minimum values and their indices along the given axis of the tensor.

Parameters
  • axis (Union[int, None], optional) – Specify the axis for computation. If None , compute all elements in the tensor. Default 0 .

  • keep_dims (bool, optional) – Whether the output tensor has dim retained. Default False .

Returns

Tuple(min, min_indices) of 2 tensors.

Supported Platforms:

Ascend GPU CPU

Examples

>>> 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=1, keep_dims=True)
(Tensor(shape=[], dtype=Int64, value= -7),
 Tensor(shape=[], dtype=Int64, value= 0))