argmin#
- ivy.argmin(x, /, *, axis=None, keepdims=False, dtype=None, select_last_index=False, out=None)[source]#
Return 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
], default:None
) – axis along which to search. If None, the function must return the index of the minimum value of the flattened array. Default = None.keepdims (
bool
, default:False
) – if True, the reduced axes (dimensions) must be included in the result as 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.dtype (
Optional
[Union
[Dtype
,NativeDtype
]], default:None
) – An optional output_dtype from: int32, int64. Defaults to int64.select_last_index (
bool
, default:False
) – If this is set to True, the index corresponding to the last occurrence of the maximum value will be returned.out (
Optional
[Array
], default:None
) – if axis is None, a zero-dimensional array containing the index of the first 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:
- 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((3,1), 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) }
- Array.argmin(self, /, *, axis=None, keepdims=False, 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
], default:None
) – axis along which to search. If None, the function must return the index of the minimum value of the flattened array. Default = None.keepdims (
bool
, default:False
) – if True, the reduced axes (dimensions) must be included in the result as 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.dtype (
Optional
[Union
[int32, int64]], default:None
) – An optional output_dtype from: int32, int64. Defaults to int64.select_last_index (
bool
, default:False
) – If this is set to True, the index corresponding to the last occurrence of the minimum value will be returned.out (
Optional
[Array
], default:None
) – if axis is None, a zero-dimensional array containing the index of the first 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((3,1), dtype=ivy.int64) >>> x.argmin(axis=1, keepdims=True, out=y) >>> print(y) ivy.array([[2], [0], [1]])
- Container.argmin(self, /, *, axis=None, keepdims=False, 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
[Union
[int
,Container
]], default:None
) – axis along which to search. If None, the function must return the index of the minimum value of the flattened array. Default = None.keepdims (
Union
[bool
,Container
], default:False
) – if True, the reduced axes (dimensions) must be included in the result as 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.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – An optional output_dtype from: int32, int64. Defaults to int64.out (
Optional
[Container
], default:None
) – optional output container, for writing the result to. It must have a shape 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]]) }