Python Numpy – Get Maximum Value of Array

Python Maximum Value of Numpy Array

Given a numpy array, you can find the maximum value of all the elements in the array.

To get the maximum value of a Numpy Array, you can use numpy function 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.

Example 1: Get 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(arr)
#find maximum value
max_value = np.max(arr)
print('Maximum value of the array is',max_value)
Run

Output

[[3 2 2 2 2]
 [5 7 0 4 5]
 [8 1 4 8 4]
 [2 0 7 2 1]]
Maximum value of the array is 8

Example 2: Find Max 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(arr)
#find maximum value
max_value = np.max(arr)
print('Maximum value of the array is',max_value)
Run

Output

[[0.79794919 0.8307877  0.83587084]
 [0.44121629 0.69983604 0.30791677]]
Maximum value of the array is 0.8358708362776799

Summary

In this Numpy Tutorial of Python Examples, we learned how to find the maximum value of Numpy Array using max() built-in function, with the help of well detailed examples.