Page9/12
Linear Algebra — Matrices & Decomposition · Page 1 of 1
Matrix Operations
Linear Algebra — Matrices & Decomposition
Matrix Multiplication
The fundamental operation in machine learning and data science.
A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6], [7, 8]])
# Element-wise multiplication
A * B # [[5, 12], [21, 32]]
# Matrix multiplication (dot product)
A @ B # or np.dot(A, B)
# [[1*5 + 2*7, 1*6 + 2*8],
# [3*5 + 4*7, 3*6 + 4*8]]
Why This Matters
- Neural networks use matrix multiplication for forward pass
- Linear regression solves:
X @ w = y - Dimensionality reduction (PCA) uses matrix decomposition
Solving Linear Systems
# Ax = b → x = A^(-1) @ b
A = np.array([[1, 2], [3, 4]])
b = np.array([5, 6])
x = np.linalg.solve(A, b)
Eigenvalues & Eigenvectors
Used in PCA, spectral clustering, and network analysis:
evals, evecs = np.linalg.eig(A) # eigenvalues and eigenvectors
Common Matrix Decompositions
| Method | Formula | Use Case |
|---|---|---|
| Inverse | A^(-1) | Solving Ax = b |
| Determinant | det(A) | Invertibility check |
| SVD | U @ S @ V.T | PCA, image compression |
| Cholesky | L @ L.T | Gaussian processes |
| QR | Q @ R | Least squares fitting |
main.py
Loading...
OUTPUT
▶Click "Run Code" to execute…