NumPy covers core LA; SciPy extends with sparse matrices, decompositions (SVD, QR), and optimizers. This lesson previews workflows that bridge both libraries.
SVD intuition
Singular Value Decomposition factorizes a matrix for dimensionality reduction and pseudoinverse. NumPy: np.linalg.svd; production-scale sparse SVD lives in SciPy.
Least squares
import numpy as np
A = np.array([[1, 1], [1, 2], [1, 3]])
y = np.array([2, 3, 4])
coef, _, _, _ = np.linalg.lstsq(A, y, rcond=None)
print(coef)
ML connection
Linear regression weights, PCA components, and neural net layers all reduce to matrix operations on ndarrays.
Important interview questions and answers
- Q: lstsq vs solve?
A: lstsq handles overdetermined/underdetermined systems—minimizes residual. - Q: When SciPy over NumPy?
A: Sparse matrices, advanced decompositions, special functions.
Self-check
- What does SVD stand for?
- Which NumPy function fits linear regression coefficients?
Tip: Continue decompositions and sparse LA at SciPy.
Interview prep
- lstsq?
Least squares fit—overdetermined linear systems.
- SVD?
Matrix factorization for PCA, pseudoinverse—SciPy for sparse variants.