Skip to main content
v2026.11,858 entries · CC-BY 4.0

NumPy min: np.min Syntax, axis, NaN Handling and nanmin

np.min finds the smallest value in a NumPy array. Covers axis, where and initial, why NaN propagates, and when to use nanmin, minimum or argmin.

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>).

  1. Create an array. a = np.arange(4).reshape((2, 2)) gives [[0, 1], [2, 3]]. For more on building arrays, see NumPy arrays.
  2. Minimum of everything. By default the input is flattened: np.min(a) returns 0.
  3. Minimum along an axis. np.min(a, axis=0) returns array([0, 1]) (one value per column); np.min(a, axis=1) returns array([0, 2]) (one value per row). If axis is a tuple of ints, the minimum is taken over several axes at once.
  4. Mask values with where and initial. np.min(a, where=[False, True], initial=10, axis=0) returns array([10, 1]). The where argument selects the elements to compare, and initial is required whenever where could 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

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about NumPy min: np.min Syntax, axis, NaN Handling and nanmin

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.