🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEnumpy

numpy Documentation

LOADING ENGINE...

np.min()

AI & DATA SCIENCE // np-min

np.min() returns the smallest value in an array, either over the entire array or along a specified axis.

Syntax

np.min(arr, axis=None)
arr.min()

Deep Dive Course

np.min(arr) and arr.min() are equivalent, both scanning the array for its smallest value; with an axis argument on a multi-dimensional array, it instead returns the minimum along that axis, collapsing it into an array of minimums, one per remaining position. Unlike Python's built-in min(), which works on any iterable of comparable objects, np.min() is specifically optimized for numeric ndarrays and computes at C speed.

1Understanding np.min()

np.min(arr) and arr.min() are equivalent, both scanning the array for its smallest value; with an axis argument on a multi-dimensional array, it instead returns the minimum along that axis, collapsing it into an array of minimums, one per remaining position. Unlike Python's built-in min(), which works on any iterable of comparable objects, np.min() is specifically optimized for numeric ndarrays and computes at C speed.

💡

For multiple arrays combined element-wise, use np.minimum(a, b) instead of np.min() — np.min() finds the smallest value within a single array, or along an axis, while np.minimum() compares two arrays element-wise and keeps the smaller value at each position.

editor.html
import numpy as np

arr = np.array([5, 2, 8, 1, 9])
print(np.min(arr))
localhost:3000

2Practical Example

Here is a real-world application of np.min() showing how it is used in production NumPy code.

editor.html
import numpy as np

a = np.array([1, 5, 3])
b = np.array([4, 2, 6])
print(np.minimum(a, b))
localhost:3000

3Best Practices

Follow these guidelines when working with np.min():

1. Use np.min()/arr.min() for the overall or per-axis smallest value within one array

2. Use np.minimum(a, b) instead when you need an element-wise comparison between two separate arrays

3. Use np.nanmin() when NaN values in the data should be ignored rather than causing the result to be NaN

⚠️

Tip: For multiple arrays combined element-wise, use np.minimum(a, b) instead of np.min() — np.min() finds the smallest value within a single array, or along an axis, while np.minimum() compares two arrays element-wise and keeps the smaller value at each position.

editor.html
import numpy as np

arr = np.array([5, 2, 8, 1, 9])
print(np.min(arr))
localhost:3000

Examples

Example 01Basic Usage
import numpy as np

arr = np.array([5, 2, 8, 1, 9])
print(np.min(arr))
Example 02Advanced Example
import numpy as np

a = np.array([1, 5, 3])
b = np.array([4, 2, 6])
print(np.minimum(a, b))

Best Practices

  • Use np.min()/arr.min() for the overall or per-axis smallest value within one array
  • Use np.minimum(a, b) instead when you need an element-wise comparison between two separate arrays
  • Use np.nanmin() when NaN values in the data should be ignored rather than causing the result to be NaN

Interview Question

What's the difference between np.min(arr) and np.minimum(a, b)?

Hint: Think about how many arrays each function operates on, and what kind of result each produces.

np.min() operates on a single array, or along one axis of it, and reduces it down to its smallest value, or an array of smallest values if reducing along one axis of a multi-dimensional input. np.minimum() instead takes two arrays of compatible shape and compares them element-wise, position by position, returning an array of the same shape where each position holds whichever of the two inputs was smaller at that position — it's a comparison between arrays, not a reduction within one.

Exercises

MediumPractice using np.min() in a real scenario.
View Solution
import numpy as np

arr = np.array([5, 2, 8, 1, 9])
print(np.min(arr))

Frequently Asked Questions

What's the difference between np.min(arr) and np.minimum(a, b)?

np.min() operates on a single array, or along one axis of it, and reduces it down to its smallest value, or an array of smallest values if reducing along one axis of a multi-dimensional input. np.minimum() instead takes two arrays of compatible shape and compares them element-wise, position by position, returning an array of the same shape where each position holds whichever of the two inputs was smaller at that position — it's a comparison between arrays, not a reduction within one.

Related Functions

np-maxnp-argminnp-clip