numpy.amin() in Python
Last Updated :
28 Apr, 2022
The numpy.amin() function returns minimum of an array or minimum along axis(if mentioned). Syntax : numpy.amin(arr, axis = None, out = None, keepdims = <class numpy._globals._NoValue>) Parameters :
- arr : [array_like]input data
- axis : [int or tuples of int]axis along which we want the min value. Otherwise, it will consider arr to be flattened.
- out : [ndarray, optional]Alternative output array in which to place the result
- keepdims : [boolean, optional]If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. If the default value is passed, then keepdims will not be passed through to the all method of sub-classes of ndarray, however any non-default value will be. If the sub-classes sum method does not implement keepdims any exceptions will be raised.
Return : Minimum of array – arr[ndarray or scalar], scalar if axis is None; the result is an array of dimension a.ndim – 1, if axis is mentioned. Code –
Python
import numpy as geek
arr = geek.arange( 8 )
print ("arr : ", arr)
print (" Min of arr : ", geek.amin(arr))
arr = geek.arange( 10 ).reshape( 2 , 5 )
print ("\narr : ", arr)
print ("\nMin of arr, axis = None : ", geek.amin(arr))
print (" Min of arr, axis = 0 : ", geek.amin(arr, axis = 0 ))
print (" Min of arr, axis = 1 : ", geek.amin(arr, axis = 1 ))
|
Output –
arr : [0 1 2 3 4 5 6 7]
Min of arr : 0
arr : [[0 1 2 3 4]
[5 6 7 8 9]]
Min of arr, axis = None : 0
Min of arr, axis = 0 : [0 1 2 3 4]
Min of arr, axis = 1 : [0 5]
References – https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.amin.html#numpy.amin
Note – These codes won’t run on online IDE’s. So please, run them on your systems to explore the working.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...