argmin

ivy.argmin(x, /, *, axis=None, keepdims=False, output_dtype=None, select_last_index=False, out=None)[source]

Returns the indices of the minimum values along a specified axis. When the minimum value occurs multiple times, only the indices corresponding to the first occurrence are returned.

Parameters
  • x (Union[Array, NativeArray]) – input array. Should have a numeric data type.

  • axis (Optional[int]) – axis along which to search. If None, the function must return the index of the (default: None) minimum value of the flattened array. Default = None.

  • keepdims (bool) – if True, the reduced axes (dimensions) must be included in the result as (default: False) singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default = False.

  • output_dtype (Optional[Union[Dtype, NativeDtype]]) – An optional output_dtype from: int32, int64. Defaults to int64. (default: None)

  • out (Optional[Array]) – if axis is None, a zero-dimensional array containing the index of the first (default: None) occurrence of the minimum value; otherwise, a non-zero-dimensional array containing the indices of the minimum values. The returned array must have the default array index data type.

Return type

Array

Returns

ret – Array containing the indices of the minimum values across the specified axis.

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Examples

With ivy.Array input:

>>> x = ivy.array([0., 1., -1.])
>>> y = ivy.argmin(x)
>>> print(y)
ivy.array(2)
>>> x = ivy.array([[0., 1., -1.],[-2., 1., 2.]])
>>> y = ivy.argmin(x, axis=1)
>>> print(y)
ivy.array([2, 0])
>>> x = ivy.array([[0., 1., -1.],[-2., 1., 2.]])
>>> y = ivy.argmin(x, axis=1, keepdims=True)
>>> print(y)
ivy.array([[2],
          [0]])
>>> x = ivy.array([[0., 1., -1.],[-2., 1., 2.],[1., -2., 0.]])
>>> y= ivy.zeros((1,3), dtype=ivy.int64)
>>> ivy.argmin(x, axis=1, keepdims=True, out=y)
>>> print(y)
ivy.array([[2],
           [0],
           [1]])

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([0., -1., 2.]), b=ivy.array([3., 4., 5.]))
>>> y = ivy.argmin(x)
>>> print(y)
{
    a:ivy.array(1),
    b:ivy.array(0)
}
ivy.Array.argmin(self, /, *, axis=None, keepdims=False, output_dtype=None, select_last_index=False, out=None)[source]

ivy.Array instance method variant of ivy.argmin. This method simply wraps the function, and so the docstring for ivy.argmin also applies to this method with minimal changes.

Parameters
  • self (Array) – input array. Should have a numeric data type.

  • axis (Optional[int]) – axis along which to search. If None, the function must return the index of (default: None) the minimum value of the flattened array. Default = None.

  • keepdims (bool) – if True, the reduced axes (dimensions) must be included in the result as (default: False) singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default = False.

  • output_dtype (Optional[Union[int32, int64]]) – An optional output_dtype from: int32, int64. Defaults to int64. (default: None)

  • out (Optional[Array]) – if axis is None, a zero-dimensional array containing the index of the first (default: None) occurrence of the minimum value; otherwise, a non-zero-dimensional array containing the indices of the minimum values. The returned array must have the default array index data type.

Return type

Union[Array, int]

Returns

ret – Array containing the indices of the minimum values across the specified axis.

Examples

Using ivy.Array instance method:

>>> x = ivy.array([0., 1., -1.])
>>> y = x.argmin()
>>> print(y)
ivy.array(2)
>>> x = ivy.array([[0., 1., -1.],[-2., 1., 2.],[1., -2., 0.]])
>>> y= ivy.zeros((1,3), dtype=ivy.int64)
>>> x.argmin(axis=1, keepdims=True, out=y)
>>> print(y)
ivy.array([[2],
           [0],
           [1]])
ivy.Container.argmin(self, /, *, axis=None, keepdims=False, output_dtype=None, select_last_index=False, out=None)[source]

ivy.Container instance method variant of ivy.argmin. This method simply wraps the function, and so the docstring for ivy.argmin also applies to this method with minimal changes.

Parameters
  • self (Container) – input array or container. Should have a numeric data type.

  • axis (Optional[int]) – axis along which to search. If None, the function must return the index of (default: None) the minimum value of the flattened array. Default = None.

  • keepdims (bool) – if True, the reduced axes (dimensions) must be included in the result as (default: False) singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default = False.

  • output_dtype (Optional[Union[Dtype, NativeDtype]]) – An optional output_dtype from: int32, int64. Defaults to int64. (default: None)

  • out (Optional[Container]) – optional output container, for writing the result to. It must have a shape (default: None) that the inputs broadcast to.

Return type

Container

Returns

ret – a container containing the indices of the minimum values across the specified axis.

Examples

Using ivy.Container instance method:

>>> x = ivy.Container(a=ivy.array([0., -1., 2.]), b=ivy.array([3., 4., 5.]))
>>> y = x.argmin()
>>> print(y)
{
    a:ivy.array(1),
    b:ivy.array(0)
}
>>> x = ivy.Container(a=ivy.array([[4., 0., -1.], [2., -3., 6]]),    ...                   b=ivy.array([[1., 2., 3.], [1., 1., 1.]])
>>> y = x.argmin(axis=1, keepdims=True)
>>> print(y)
{
    a: ivy.array([[2],
                  [1]]),
    b: ivy.array([[0],
                  [0]])
}
ivy.Container.static_argmin(x, /, *, axis=None, keepdims=False, output_dtype=None, select_last_index=False, out=None)[source]

ivy.Container static method variant of ivy.argmin. This method simply wraps the function, and so the docstring for ivy.argmin also applies to this method with minimal changes.

Parameters
  • x (Union[Container, Array, NativeArray]) – input array or container. Should have a numeric data type.

  • axis (Optional[int]) – axis along which to search. If None, the function must return the index of (default: None) the minimum value of the flattened array. Default = None.

  • keepdims (bool) – if True, the reduced axes (dimensions) must be included in the result as (default: False) singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default = False.

  • output_dtype (Optional[Union[int32, int64]]) – An optional output_dtype from: int32, int64. Defaults to int64. (default: None)

  • out (Optional[Container]) – optional output container, for writing the result to. It must have a shape (default: None) that the inputs broadcast to.

Return type

Container

Returns

ret – a container containing the indices of the minimum values across the specified axis.

Examples

>>> x = ivy.Container(a=ivy.array([[4., 0., -1.], [2., -3., 6]]),    ...                   b=ivy.array([[1., 2., 3.], [1., 1., 1.]])
>>> y = ivy.Container.static_argmin(axis=1, keepdims=True)
>>> print(y)
{
    a: ivy.array([[2],
                  [1]]),
    b: ivy.array([[0],
                  [0]])
}

Supported Frameworks: