Member-only story
Linear Algebra for Data Science — Part 2
Matrix Addition, Subtraction and Multiplication
In part 1 of this series on Linear Algebra, we learn some basic concepts about matrices, and how to perform elementary row operations. In this second chapter, we will learn about matrix addition, subtraction, and multiplications.
If you haven’t read part 1, I strongly recommend you go back and read it.
Matrix Addition
Adding matrices is a very straightforward operation that only requires one assumption: the two matrices to be added must be the same shape. Let’s see an example:
import numpy as npa = np.array([[1,2,3], [4,5,6], [7,8,9]])
b = np.array([[3,2,1], [6,5,6], [1,1,1]])print('A=',a)
print('\n')
print('B=',b)
print('\n')
print('Shape of A is:', a.shape)
print('Shape of B is:', b.shape)
We have matrix A and matrix B, and both matrices have the same shape (3x3). To…