argmin

paddle. argmin ( x, axis=None, keepdim=False, dtype='int64', name=None ) [source]

Computes the indices of the min elements of the input tensor’s element along the provided axis.

Parameters
  • x (Tensor) – An input N-D Tensor with type float16, float32, float64, int16, int32, int64, uint8.

  • axis (int, optional) – Axis to compute indices along. The effective range is [-R, R), where R is x.ndim. when axis < 0, it works the same way as axis + R. Default is None, the input x will be into the flatten tensor, and selecting the min value index.

  • keepdim (bool, optional) – Whether to keep the given axis in output. If it is True, the dimensions will be same as input x and with size one in the axis. Otherwise the output dimensions is one fewer than x since the axis is squeezed. Default is False.

  • dtype (str, optional) – Data type of the output tensor which can be int32, int64. The default value is ‘int64’, and it will return the int64 indices.

  • name (str, optional) – For details, please refer to Name. Generally, no setting is required. Default: None.

Returns

Tensor, return the tensor of int32 if set dtype is int32, otherwise return the tensor of int64.

Examples

>>> import paddle

>>> x =  paddle.to_tensor([[5,8,9,5],
...                        [0,0,1,7],
...                        [6,9,2,4]])
>>> out1 = paddle.argmin(x)
>>> print(out1.numpy())
4
>>> out2 = paddle.argmin(x, axis=0)
>>> print(out2.numpy())
[1 1 1 2]
>>> out3 = paddle.argmin(x, axis=-1)
>>> print(out3.numpy())
[0 0 2]
>>> out4 = paddle.argmin(x, axis=0, keepdim=True)
>>> print(out4.numpy())
[[1 1 1 2]]