bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / argmin
_ArrayFunctionDispatcher
numpy:argmin
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/_core/fromnumeric.py :1321
Signature
def argmin ( a , axis = None , out = None , * , keepdims = <no value> ) Summary
Returns the indices of the minimum values along an axis.
Parameters
a: array_likeInput array.
axis: int, optionalBy default, the index is into the flattened array, otherwise along the specified axis.
out: array, optionalIf provided, the result will be inserted into this array. It should be of the appropriate shape and dtype.
keepdims: bool, optionalIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.
Returns
index_array: ndarray of intsArray of indices into the array. It has the same shape as
a.shapewith the dimension alongaxisremoved. Ifkeepdimsis set to True, then the size ofaxiswill be 1 with the resulting array having same shape asa.shape.
Notes
In case of multiple occurrences of the minimum values, the indices corresponding to the first occurrence are returned.
Examples
import numpy as np a = np.arange(6).reshape(2,3) + 10 a✓
np.argmin(a)
✗np.argmin(a, axis=0) np.argmin(a, axis=1)✓
a.flat[np.argmin(a)]
✗ind = np.unravel_index(np.argmin(a, axis=None), a.shape)
✓ind a[ind]✗
b = np.arange(6) + 10 b[4] = 10 b✓
np.argmin(b) # Only the first occurrence is returned.
✗x = np.array([[4,2,3], [1,0,3]]) index_array = np.argmin(x, axis=-1) np.take_along_axis(x, np.expand_dims(index_array, axis=-1), axis=-1) np.take_along_axis(x, np.expand_dims(index_array, axis=-1), axis=-1).squeeze(axis=-1)✓
x = np.arange(24).reshape((2, 3, 4)) res = np.argmin(x, axis=1, keepdims=True) res.shape✓
See also
- amin
The minimum value along a given axis.
- argmax
- ndarray.argmin
- take_along_axis
Apply
np.expand_dims(index_array, axis)from argmin to an array as if by calling min.- unravel_index
Convert a flat index into an index tuple.
Aliases
-
numpy.argmin