Python Program - Maximum Value of Numpy Array - numpy.max()
Numpy - Maximum Value in Array
Given a numpy array, you can find the maximum value of all elements in the array.
To get the maximum value of a NumPy Array, you can use numpy.max()
function.
Syntax
The syntax of max() function as given below.
max_value = numpy.max(arr)
Pass the numpy array as argument to numpy.max(), and this function shall return the maximum value.
Examples
1. Maximum value of numpy array
In this example, we will take a numpy array with random numbers and then find the maximum of the array using numpy.max() function.
Python Program
import numpy as np
arr = np.random.randint(10, size=(4,5))
print('array\n', arr)
#find maximum value
max_value = np.max(arr)
print('Maximum value in array\n',max_value)
Output
[[8 8 5 3 0]
[2 0 4 5 1]
[4 7 0 1 5]
[5 2 1 5 8]]
Maximum value in array
8
2. Maximum value of numpy array with float values
In the following example, we will take a numpy array with random float values and then find the maximum of the array using max() function.
Python Program
import numpy as np
arr = np.random.rand(6).reshape(2,3)
print('array\n', arr)
#find maximum value
max_value = np.max(arr)
print('Maximum value in array\n',max_value)
Output
array
[[0.45733784 0.70319461 0.65038256]
[0.77489769 0.71777846 0.89612105]]
Maximum value in array
0.8961210501172747
Summary
In this Numpy Tutorial, we learned how to find the maximum value in Numpy Array using numpy.max() function, with well detailed examples.