Comparing Maximum from Matrices | Linear Algebra using Python

Linear Algebra using Python | Comparing Maximum from Matrices: Here, we are going to learn about the comparing maximum from matrices and its implementation in Python.
Submitted by Anuj Singh, on June 08, 2020

Prerequisites:

Learn: how to find the maximum value from comparison of each element in two matrices using an inbuilt function in the numpy library?

Syntax:

numpy.maximum(Matrix_M1, Matrix_M2)

Return:

A matrix of same dimension with given matrix containing maximum value at each entry among both matrices.

Python code for comparing maximum from matrices

# Linear Algebra Learning Sequence
# Maximum Value Comparing

import numpy as np

M = np.array([[2,3,4], [4,4,8], [4,8455,7], [4,8,99] ])
MM = np.array([[2,3,46], [4,44,8], [4,8,7], [4,8,9] ])
print("\n\n---Matrix A---\n", M)
print("\n\n---Matrix B---\n", MM)
print('\n\n---maximum value comparasion : ', np.maximum(M,MM))

Output:



---Matrix A---
 [[   2    3    4]
 [   4    4    8]
 [   4 8455    7]
 [   4    8   99]]


---Matrix B---
 [[ 2  3 46]
 [ 4 44  8]
 [ 4  8  7]
 [ 4  8  9]]


---maximum value comparasion :  [[   2    3   46]
 [   4   44    8]
 [   4 8455    7]
 [   4    8   99]]


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.