numpy.min() in Python | np.min() in Python

Numpy min() function is used to get a minimum value along a specified axis.

Syntax of Numpy.min()

np.min(a, axis=None)

a parameter refers to the array on which you want to apply np.min() function.

axis parameter is optional and helps us to specify the axis on which we want to find the minimum values.

Python program to find minimum value on 1-Dimensional Numpy Array

import numpy as np

a = np.array([50, 15, 23, 89, 64])
print('Minimum value in arr: ', np.min(a))

Output of the above program

Minimum value in arr: 15

In 1-Dimensional, it is optional to pass axis parameter to np.min() function.

Numpy min on 1-Dimensional Array

Python program to find minimum value on 2-Dimensional Numpy Array

import numpy as np

a = np.array([[50, 15, 89, 23, 64], 
              [45, 98, 25, 17, 55], 
              [35, 37, 9, 100, 61]])
print('Minimum value in arr: ', np.min(a))
print('Minimum value in arr along axis 0: ', np.min(a, axis=0))
print('Minimum value in arr along axis 1: ', np.min(a, axis=1))

Output of the above program

Minimum value in arr:  9
Minimum value in arr along axis 0:  [35 15  9 17 55]
Minimum value in arr along axis 1:  [15 17  9]

When axis value is not passed to min() function, then it returns the minimum element present in the array-

Numpy min on 2-Dimensional Array

When axis=0 is passed to min() function, then it works like this-

Numpy min on 2-Dimensional Array with axis0

When axis=1 is passed to min() function, then it works like this-

Numpy min on 2-Dimensional Array with axis1

Recommended Posts