Playlist
• Machine Learning with Python
2023 09 17 14 20 22
1.8 Finding the Maximum and Minimum
Values
Problem
You need to find the maximum or minimum value in an array.
Solution
Use NumPy’s max and min methods:
Load library
import numpy as np
Create matrix
matrix = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
Return maximum element
np.max(matrix)
9
Return minimum element
np.min(matrix)
1
Discussion
Often we want to know the maximum and minimum value in an array or
subset of an array. This can be accomplished with the max and min
methods. Using the axis parameter, we can also apply the operation along
a certain axis:
Find maximum element in each column
np.max(matrix, axis=0)
array([7, 8, 9])
Find maximum element in each row
np.max(matrix, axis=1)
array([3, 6, 9])ll elements of a NumPy array
On this page of the site you can watch the video online NumPy: Finding the Maximum and Minimum Values with a duration of hours minute second in good quality, which was uploaded by the user Le Hoang Long Long 17 September 2023, share the link with friends and acquaintances, this video has already been watched 13 times on youtube and it was liked by 0 viewers. Enjoy your viewing!