Chapter 09
1.8 Linear Algebra Refresher
1.8 Linear Algebra Refresher
![]()
Notes
Linear Algebra Refresher
- Vector operations
- Multiplication
- Vector-vector multiplication
- Matrix-vector multiplication
- Matrix-matrix multiplication
- Identity matrix
- Inverse
Vector operations
python
u = np.array([2, 7, 5, 6])
v = np.array([3, 4, 8, 6])
# addition
u + v
# subtraction
u - v
# scalar multiplication
2 * vMultiplication
Vector-vector multiplication
python
def vector_vector_multiplication(u, v):
assert u.shape[0] == v.shape[0]
n = u.shape[0]
result = 0.0
for i in range(n):
result = result + u[i] * v[i]
return resultMatrix-vector multiplication
python
def matrix_vector_multiplication(U, v):
assert U.shape[1] == v.shape[0]
num_rows = U.shape[0]
result = np.zeros(num_rows)
for i in range(num_rows):
result[i] = vector_vector_multiplication(U[i], v)
return resultMatrix-matrix multiplication
python
def matrix_matrix_multiplication(U, V):
assert U.shape[1] == V.shape[0]
num_rows = U.shape[0]
num_cols = V.shape[1]
result = np.zeros((num_rows, num_cols))
for i in range(num_cols):
vi = V[:, i]
Uvi = matrix_vector_multiplication(U, vi)
result[:, i] = Uvi
return resultIdentity matrix
python
I = np.eye(3)Inverse
python
V = np.array([
[1, 1, 2],
[0, 0.5, 1],
[0, 2, 1],
])
inv = np.linalg.inv(V)Add notes here (PRs are welcome).
- Notes from Peter Ernicke - Part 1/3
- Notes from Peter Ernicke - Part 2/3
- Notes from Peter Ernicke - Part 3/3
Links
- Notebook from the video
- Get a visual understanding of matrix multiplication
- Overview of matrix multiplication functions in python/numpy
