.min()
Published Jun 9, 2025
Contribute to Docs
The NumPy function .min()
returns the minimum value in an array. It can compute the minimum of the entire array, the minimum along specific axes, or the minimum of selected elements if indexing or conditions are applied.
Syntax
numpy.min(a, axis=None, out=None, keepdims=<no value>, initial=<no value>, where=<no value>)
Parameters:
a
: The input array or sequence of numbers from which the minimum value is to be determined.axis
(optional): Axis or axes along which to compute the minimum.axis=0
returns minimums for each column (vertical).axis=1
returns minimums for each row (horizontal).- A tuple like
(0, 1)
computes over multiple axes (e.g., the entire array for a 2D input).
out
(optional): Alternative output array to store the result. Must have the same shape as the expected output.keepdims
(optional): IfTrue
, retains reduced dimensions with size 1. This is useful for broadcasting in further operations.initial
(optional): Starting value for the comparison. Useful when usingwhere
or to set a baseline minimum.where
(optional): A boolean mask array that specifies elements to include in the comparison. If used,initial
must be provided to avoid empty comparisons.
Return value:
min
: The minimum value ofa
.- If
axis
isNone
, returns the overall minimum as a scalar. - If
axis
is specified, returns an array with the minimum values along the given axis (or axes). The shape is reduced accordingly, unlesskeepdims=True
.
- If
Example
This example shows how to find the minimum value of an entire array and along specific axes:
import numpy as np# Create a 2D arrayarr = np.array([[1, 2, 3],[4, 5, 6]])# Finding the minimum value of the arraymin_of_arr = np.min(arr)# Finding the minimum value of each column in the arraymin_of_col = np.min(arr, axis=0)# Finding the minimum value of each row in the arraymin_of_row = np.min(arr, axis=1)# Print the resultsprint("The array:")print(arr)print("\nThe minimum value:")print(min_of_arr)print("The minimum value of each column:")print(min_of_col)print("The minimum value of each row:")print(min_of_row)
The output of this code is:
The array:[[1 2 3][4 5 6]]The minimum value:1The minimum value of each column:[1 2 3]The minimum value of each row:[1 4]
Codebyte Example
Run the following code to understand how the .min()
works with the where
parameter:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:NumPy on Codecademy
- Career path
Data Scientist: Machine Learning Specialist
Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.Includes 27 CoursesWith Professional CertificationBeginner Friendly95 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours