Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

NumPy · Function

np.argmin

Returns the indices of minimum values in an array, either globally or along a chosen axis. It can preserve reduced dimensions and optionally write into a supplied output array.

How it works

np.argmin returns integer positions of minimum elements. With axis=None it searches the flattened input; with an axis it reduces that dimension, and keepdims=True retains it with size one. When equal minima occur, it selects the first occurrence.

Syntax

numpy.argmin(a, axis=None, out=None, *, keepdims=<no value>)

Parameters

NameTypeDescription
aarray_likeInput array.
axisint, optionalReduction axis. By default, indexing is performed into the flattened array; otherwise it is performed along the specified axis.
outarray, optionalDestination array into which the result is inserted; it must have the appropriate shape and dtype.
keepdimsbool, optionalWhether reduced axes remain in the result with length one.

Returns

index_array: ndarray of ints. Indices into the input array; its shape matches a.shape with the reduction axis removed, or retains that axis at size one when keepdims=True.

Key points

  • Use np.argmin when you need locations of minima rather than the minimum values themselves.
  • Omitting axis searches a flattened view conceptually; supplying an integer axis performs independent reductions along that dimension.
  • Pass out to store the result in a preallocated destination.
  • keepdims preserves reduced axes as singleton dimensions.
  • The singleton dimensions created by keepdims can simplify broadcasting with the input.

Common mistakes

  • Ties are resolved by returning the index of the first minimum encountered.

Example: Find minimum-value indices

import numpy as np

a = np.array([[4, 1, 7], [2, 9, 0]])
print(np.argmin(a))
print(np.argmin(a, axis=0))
print(np.argmin(a, axis=1, keepdims=True))

The default searches the flattened array; specifying an axis returns minimum positions along that axis, while keepdims preserves the reduced dimension.

When to use it

Global minimum location

Locate the smallest element in a vector or multidimensional array.

Per-axis selection

Find the best or lowest-valued option independently across rows or columns.

Broadcast-friendly reductions

Keep reduction results shape-compatible with the source for later broadcasting.

Interview questions

QWhat does np.argmin return, and how does axis affect it?

It returns an integer array containing the positions of minimum values. With axis=None, the position refers to the flattened array; with an axis, the reduction happens independently along that axis.

Follow-up: How can the result retain the reduced dimension? Set keepdims=True, which leaves that axis present with length one.

QHow are ties handled?

If several elements share the minimum value, np.argmin returns the index associated with the first occurrence. This applies to the selected search domain, whether flattened or along an axis.

Follow-up: How would you obtain the minimum value itself? Use np.min or the array's minimum operation rather than np.argmin.

QWhen is keepdims useful?

keepdims=True leaves each reduced axis in the output with size one. This makes the result shape compatible for broadcasting against the original array.

Follow-up: What must be true when using out? The destination must have the appropriate shape and dtype for the result.

  • numpy.ndarray.argmin
  • numpy.argmax
  • numpy.amin

Source: numpy.argmin. Checked 2026-10-15.