scipy.linalghamesha ek optimized, complete LAPACK/BLAS ke saath compiled hoti hai; numpy kabhi kabhi
build ke hisaab se slower/less-complete routines pe fall back kar sakti hai.
scipy aapko stable algorithm explicitly choose karne deti hai (jaise solve karo LU with partial pivoting se,
ya Cholesky se agar SPD hai) ek hi ek general path ke bajaye.
Kabhi inv(A) @ b mat compute karo — wahi asli instability hai. solve/factorizations use karo.
import numpy as npfrom scipy.linalg import lu, lu_factor, lu_solve, solveA = np.array([[2.,1.],[6.,5.]]); b = np.array([3.,17.])P, L, U = lu(A) # SciPy convention: P @ A = L @ U (so A = P.T @ L @ U)x = solve(A, b) # the right way to solve -> x = [-0.5, 4.]lu_piv = lu_factor(A) # reuse factorization for many b'sx2 = lu_solve(lu_piv, b)
from scipy.linalg import qr, lstsqQ, R = qr(A, mode='economic') # economic: Q is m×n, R is n×nx, res, rank, sv = lstsq(A, b) # robust least squares (uses SVD/QR internally)
from scipy.linalg import schur, eigT, Z = schur(A) # A = Z @ T @ Z.conj().Tw, vl, vr = eig(A, left=True) # scipy gives left+right eigenvectors# generalized eigenproblem A x = λ B x (numpy can't do this!):w_gen = eig(A, b=np.eye(len(A)))
Recall Feynman: 12 saal ke bacche ko explain karo
Socho ek ulsajhi hui machine hai jo arrows ko ghuma-marod deti hai. Us uljhan ko seedha samajhna mushkil hai.
Toh hum us machine ko simple pieces mein todh dete hain: ek piece sirf stretch karta hai (triangular), ek piece
sirf spin karta hai bina stretch kiye (orthogonal/unitary). Jab yeh simple pieces mein aa jaaye, tab sawaalon ka
jawab dena — "kaunsa arrow khud jaisa hi nikalta hai?" (eigenvalues) ya "machine ko undo karo taaki original arrow
wapas mile" (solve Ax=b) — aasaan ho jaata hai. scipy.linalg woh toolbox hai jo yeh clean breaks
carefully karta hai taaki chhoti rounding mistakes phail na jaayein.
Why use scipy.linalg over numpy.linalg?
Full LAPACK interface (lu, qr, schur, cho_factor, generalized eig), hamesha optimized LAPACK/BLAS se linked, aur stable algorithm explicitly choose karne deta hai.
What is the LU factorization with pivoting?
PA=LU — P permutation (stability ke liye row swaps), L unit-lower-triangular (elimination multipliers), U upper triangular.
How do you solve Ax=b once you have PA=LU?
Forward-solve Ly=Pb, phir back-solve Ux=y.
Why never compute inv(A)@b?
~3× zyada flops aur rounding error amplify karta hai; solve()/factorizations use karo.
What convention does scipy.linalg.lu return?
P, L, U with P @ A = L @ U (equivalently A = P.T @ L @ U), NOT A = P @ L @ U.
Define QR factorization.
A=QR jahan Q orthogonal hai (QTQ=I) aur R upper triangular hai.
Why does QR solve least squares stably?
Orthogonal Q length preserve karta hai, toh min reduce ho jaata hai Rx=QTb par; normal equations se bachta hai jo condition number square kar dete hain.
What sits on the diagonal of T in the Schur form A=ZTZH?
A ke eigenvalues.
Why prefer Schur over diagonalization numerically?
Schur hamesha exist karta hai aur unitary Z use karta hai (condition number 1), defective/non-diagonalizable matrices ke liye bhi.
Which scipy feature does numpy.linalg lack for eigenproblems?
Generalized eigenproblem Ax=λBx via eig(A, b=B).
Relationship between κ(A) and the normal equations?
Normal equations ka condition number κ(A)2 hota hai, jo unhe QR se kam accurate banata hai.