Skip to content

Commit

Permalink
Update 08-linear-algebra.md (DataTalksClub#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin3005 authored Sep 8, 2022
1 parent 14fb9b1 commit 3e550e5
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions course-zoomcamp/01-intro/08-linear-algebra.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,96 @@

## 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 * v
~~~~
### Multiplication

##### 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 result
~~~~

##### Matrix-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 result
~~~~

##### Matrix-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 result
~~~~
### Identity 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).

Expand Down

0 comments on commit 3e550e5

Please sign in to comment.