numpy.amax() in Python
numpy.amax(arr, axis = None, out = None, keepdims = <class numpy._globals._NoValue>) returns maximum of an array or maximum along axis(if mentioned).
Parameters –
- arr : [array_like] input data
- axis : [int or tuples of int] axis along which we want the max value. Otherwise, it will consider arr to be flattened.
- out : [ndarray, optional] alternative output array in which to place the result
- keepdmis : [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 – Maximum 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 Program illustrating # numpy.amax() method import numpy as geek # 1D array arr = geek.arange(8) print("arr : ", arr) print("Max of arr : ", geek.amax(arr)) # 2D array arr = geek.arange(10).reshape(2, 5) print("\narr : ", arr) # Maximum of the flattened array print("\nMax of arr, axis = None : ", geek.amax(arr)) # Maxima along the first axis # axis 0 means vertical print("Max of arr, axis = 0 : ", geek.amax(arr, axis = 0)) # Maxima along the second axis # axis 1 means horizontal print("Max of arr, axis = 1 : ", geek.amax(arr, axis = 1)) |
Output –
arr : [0 1 2 3 4 5 6 7] Max of arr : 7 arr : [[0 1 2 3 4] [5 6 7 8 9]] Max of arr, axis = None : 9 Max of arr, axis = 0 : [5 6 7 8 9] Max of arr, axis = 1 : [4 9]
Reference –
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.amax.html
Note –
These codes won’t run on online-ID. Please run them on your systems to explore the working
This article is contributed by Mohit Gupta_OMG 😀. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Recommended Posts:
- How to write an empty function in Python - pass statement?
- Operator Functions in Python | Set 2
- Time Functions in Python | Set-2 (Date Manipulations)
- Send mail from your Gmail account using Python
- Python – The new generation Language
- Print Single and Multiple variable in Python
- Increment and Decrement Operators in Python
- str() vs repr() in Python
- Swap two variables in one line in C/C++, Python, PHP and Java
- Generate all permutation of a set in Python
- Class or Static Variables in Python
- trunc() in Python
- Division Operators in Python
- Interesting facts about strings in Python | Set 1
- When to use yield instead of return in Python?




