v Find The Maximum And Minimum - Machine Learning

Find The Maximum And Minimum

Preliminaries

# Load library
import numpy as np

Create Matrix

# Create matrix
matrix = np.array([[1, 2, 3],
                   [4, 5, 6],
                   [7, 8, 9]])

Find Maximum Element

# Return maximum element
np.max(matrix)
9

Find Minimum Element

# Return minimum element
np.min(matrix)
1

Find Maximum Element By Column

# Find the maximum element in each column
np.max(matrix, axis=0)
array([7, 8, 9])

Find Maximum Element By Row

# Find the maximum element in each row
np.max(matrix, axis=1)
array([3, 6, 9])