Linear algebra is the language of machine learning and graphics — a regression fit, a neural-network layer and a PCA are all matrix operations. NumPy's @ operator and np.linalg module give you the full toolkit.
Matrix products
The @ operator is matrix multiplication — not element-wise. Inner dimensions must match:
A = np.array([[1, 2], [3, 4]])B = np.array([[5, 6], [7, 8]])A @ B # matrix product (rows · columns)A * B # element-wise (a different result!)v = np.array([1, 0])A @ v # matrix–vector product → [1 3]
Solving systems
A = np.array([[3, 1], [1, 2]])b = np.array([9, 8])x = np.linalg.solve(A, b) # [2. 3.]
Properties & decompositions
np.linalg.det(A) # determinant (0 → singular)np.linalg.inv(A) # inversenp.linalg.eig(A) # eigenvalues & eigenvectorsnp.linalg.svd(A) # singular value decomposition (powers PCA)
Key takeaways
- 01@ (or np.dot) is matrix multiplication — not element-wise; inner dimensions must match.
- 02Solve Ax = b with np.linalg.solve, not by inverting A — faster and more stable.
- 03np.linalg provides det, inv, eig and svd.
- 04The SVD underlies PCA and dimensionality reduction.
