Title: Find The Maximum And Minimum Slug: find_maximum_and_minimum
Summary: How to find the maximum, minimum, and average of the elements in an array.
Date: 2017-09-03 12:00
Category: Machine Learning
Tags: Vectors Matrices Arrays
Authors: Chris Albon

Preliminaries


In [8]:
# Load library
import numpy as np

Create Matrix


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

Find Maximum Element


In [10]:
# Return maximum element
np.max(matrix)


Out[10]:
9

Find Minimum Element


In [11]:
# Return minimum element
np.min(matrix)


Out[11]:
1

Find Maximum Element By Column


In [13]:
# Find the maximum element in each column
np.max(matrix, axis=0)


Out[13]:
array([7, 8, 9])

Find Maximum Element By Row


In [14]:
# Find the maximum element in each row
np.max(matrix, axis=1)


Out[14]:
array([3, 6, 9])