Written and maintained by CASRAI Editorial Board
Last updated
np.min returns the smallest value in a NumPy array, either over the whole array or along an axis you choose. Its less obvious behaviours are what trip up research code: a single NaN makes the result NaN, the initial argument counts as a real element, and where lets you mask values without copying the array. This guide covers the signature, the shape of the result, and the choice between min, nanmin, minimum, fmin and argmin, checked against the NumPy 2.5 manual on 2026-10-29.
What np.min is used for in research
In research data work, np.min is the quick range check on a measurement array: the lowest reading per sample, the earliest timestamp, the smallest residual. Computed per column with axis=0, it gives one minimum per variable, which makes it a fast sanity check before modelling. Because NaN values propagate, a NaN result is also a cheap signal that missing data reached the calculation (see NumPy NaN handling).
Install or access
Install NumPy from the official instructions at numpy.org/install. With pip: pip install numpy. With conda, create and activate an environment, then run conda install numpy (the defaults or conda-forge channel). Confirm the install:
import numpy as np
print(np.__version__)
Step-by-step: finding a minimum
The signature in the NumPy manual is numpy.min(a, axis=None, out=None, keepdims=<no value>, initial=<no value>, where=<no value>).
- Create an array.
a = np.arange(4).reshape((2, 2))gives[[0, 1], [2, 3]]. For more on building arrays, see NumPy arrays. - Minimum of everything. By default the input is flattened:
np.min(a)returns0. - Minimum along an axis.
np.min(a, axis=0)returnsarray([0, 1])(one value per column);np.min(a, axis=1)returnsarray([0, 2])(one value per row). Ifaxisis a tuple of ints, the minimum is taken over several axes at once. - Mask values with where and initial.
np.min(a, where=[False, True], initial=10, axis=0)returnsarray([10, 1]). Thewhereargument selects the elements to compare, andinitialis required wheneverwherecould leave a slice empty.
initial is not the same as Python’s default
In NumPy, initial is used as one of the elements being compared, so np.min([6], initial=5) returns 5. Python’s built-in min([6], default=5) returns 6, because default applies only when the iterable is empty. Likewise np.min([[-50], [10]], axis=-1, initial=0) returns array([-50, 0]).
Output and how to read it
With axis=None the result is a scalar. With an int axis the result is an array with a.ndim - 1 dimensions. With a tuple of axes it has a.ndim - len(axis) dimensions. A 3-D array reduced along one axis therefore comes back 2-D.
NaN values propagate
The manual states that if at least one item is NaN, the corresponding minimum is NaN as well. With b = np.arange(5, dtype=np.float64) and b[2] = np.nan, np.min(b) returns nan. To ignore NaN values use np.nanmin, or mask them: np.min(b, where=~np.isnan(b), initial=10) returns 0.0, and so does np.nanmin(b).
Troubleshooting
The result is nan
At least one value in the slice is NaN. Use np.nanmin, or pass where=~np.isnan(a) together with an initial value larger than any real value in your data.
A RuntimeWarning from nanmin
When nanmin meets a slice that is entirely NaN, the manual says a RuntimeWarning is raised and NaN is returned for that slice. Check for all-NaN rows or columns before relying on the output.
Taking the minimum of two arrays
The manual advises against min for element-wise comparison of two arrays. Use np.minimum(x, y) instead; when a.shape[0] is 2, minimum(a[0], a[1]) is faster than min(a, axis=0).
Clamping values rather than finding the minimum
If the goal is to cap values at a lower or upper bound, see numpy clip.
Related functions (comparison table)
| Function | What it does, per the NumPy manual |
|---|---|
np.min |
Minimum of one array, over all elements or along axes; NaN propagates. |
np.nanmin |
Same, ignoring NaN. An all-NaN slice raises a RuntimeWarning and returns NaN. Positive infinity counts as a very large number and negative infinity as a very small one. For integer input it is equivalent to np.min. The initial and where arguments are new in 1.22.0. |
np.minimum |
Element-wise minimum of two arrays; propagates NaN. |
np.fmin |
Element-wise minimum of two arrays; ignores NaN. |
np.argmin |
Returns the indices of the minimum values rather than the values. Its maximum counterpart is covered in numpy argmax. |
np.max |
The maximum counterpart of np.min. |
Example from the nanmin page: with a = np.array([[1, 2], [3, np.nan]]), np.nanmin(a) returns 1.0, axis=0 returns array([1., 2.]) and axis=1 returns array([1., 3.]). Conditional selection of values before taking a minimum is covered in numpy where.
FAQ
How do I find the minimum of a NumPy array?
Call np.min(a) for the smallest value overall, or np.min(a, axis=0) for one minimum per column.
How do I ignore NaN when finding the minimum?
Use np.nanmin(a), or np.min(a, where=~np.isnan(a), initial=...) with an initial value larger than your data.
What is the difference between np.min and np.minimum?
np.min reduces one array to its smallest value(s); np.minimum compares two arrays element by element.
How do I get the position of the minimum instead of its value?
Use np.argmin, which returns the indices of the minimum values.
Is np.amin the same as np.min?
Yes. The NumPy manual states that amin is an alias of min.
Sources
- NumPy manual (v2.5), numpy.min, checked 2026-10-29.
- NumPy manual, numpy.amin, checked 2026-10-29.
- NumPy manual, numpy.nanmin, checked 2026-10-29.
- NumPy, Installing NumPy, checked 2026-10-29.








