Member-only story

Linear Algebra for Data Science — Part 2

Matrix Addition, Subtraction and Multiplication

Carla Martins
6 min readOct 25, 2022
Photo by Tyler Easton on Unsplash

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.

https://cdanielaam.medium.com/linear-algebra-for-data-science-part-1-2ce1044353e9

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…

--

--

Carla Martins
Carla Martins

Written by Carla Martins

Compulsive learner. Passionate about technology. Speaks C, R, Python, SQL, Haskell, Java and LaTeX. Interested in creating solutions.

Responses (1)