Numpy min()
function is used to get a minimum value along a specified axis.
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.
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.
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-
When axis=0
is passed to min() function, then it works like this-
When axis=1
is passed to min() function, then it works like this-