WHY not just invert? Mathematically x=A−1b. But computing A−1 is slower and less accurate than directly solving. So we never write inv(A) @ b; we write solve(A, b).
import numpy as npA = np.array([[2., 1.], [1., 3.]])b = np.array([5., 10.])x = np.linalg.solve(A, b) # array([1., 3.])np.allclose(A @ x, b) # True <- always verify!
A = np.array([[3., 0.], [0., 2.], [0., 0.]]) # 3x2, NOT square -> eig would failU, s, Vt = np.linalg.svd(A) # s is a 1D array of singular values# reconstruct:Sig = np.zeros_like(A)np.fill_diagonal(Sig, s)np.allclose(U @ Sig @ Vt, A) # True
Recall Feynman: explain to a 12-year-old
A matrix is a stretchy-twisty machine for arrows.
solve: "I see where the arrow landed; where did it start?" (run the machine backward).
det: "How much bigger did the machine make a square?" If zero, it squished everything flat — you can't un-squish, so no backward.
norm: "How long is this arrow?"
eig: "Which arrows does the machine only make longer/shorter, never turn?"
svd: "Even for weird machines: first spin the arrow, then stretch it, then spin again." The stretch numbers are the singular values.
Dekho, ek matrix ko ek "machine" samajho jo arrows (vectors) ko stretch aur twist karti hai. NumPy ka linalg module is machine ke saare kaam karta hai, aur andar se ye LAPACK (super-fast Fortran code) use karta hai, isliye tum sirf ek line likhte ho aur kaam ho jaata hai.
np.linalg.solve(A, b) ka matlab hai: Ax=b ko ulta chalाना — landing point pata hai, starting arrow dhoondo. Yaha pe ek bada lesson: kabhi inv(A) @ b mat likho, hamesha solve use karo, kyunki inverse nikalna slow bhi hai aur error bhi badha deta hai. det batata hai machine ne area/volume kitna scale kiya — agar det=0 to sab kuch ek line me squish ho gaya, matlab matrix invertible nahi. norm arrow ki lambai (size) deta hai, default Euclidean length.
eig square matrix ke liye un special directions ko dhoondta hai jinko machine sirf stretch karti hai, rotate nahi — wahi hain eigenvectors, aur stretch amount eigenvalue λ. Yaad rakho: NumPy me eigenvectors columns me aate hain, V[:, i], rows me nahi! svd sabse powerful hai — ye kisi bhi matrix (square ho ya nahi) ko todta hai: pehle ghumao (V⊤), phir stretch karo (Σ), phir ghumao (U). Ye singular values σ PCA, compression aur least-squares me kaam aate hain.
Practical tip jo exam aur real code dono me help karega: jo bhi solve/decompose karo, hamesha np.allclose(A @ x, b) ya reconstruction se check karo. Isse confidence aata hai ki numerics sahi hai. 80/20 rule: solve, svd, aur allclose — bas ye teen cheezein 80% kaam karwa dengi.