scipy.linalg extends NumPy linear algebra with decompositions (LU, QR, Cholesky), matrix functions, and numerically stable solvers for dense problems.
When scipy.linalg vs np.linalg
- Small solves: either
np.linalg.solveorlinalg.solve - Decompositions:
linalg.lu,linalg.qr,linalg.cholesky - Matrix exponentials, norms, determinants with LAPACK backends
Array dtypes
Use float64 for stability unless memory forces float32. Ill-conditioned matrices need condition number checks via linalg.cond.
Norm and det
import numpy as np
from scipy import linalg
A = np.array([[1., 2.], [3., 4.]])
print('det:', linalg.det(A))
print('norm:', linalg.norm(A))
print('cond:', linalg.cond(A))
Important interview questions and answers
- Q: Condition number?
A: Ratio relating input perturbation to output error—large cond means unstable solve. - Q: Why float64?
A: Single precision can fail subtle LA tasks; production numerics often default to double.
Self-check
- Name three scipy.linalg capabilities beyond np.linalg.solve.
- What does a large condition number warn you about?
Tip: Check linalg.cond(A) before trusting solves on nearly singular matrices.
Interview prep
- cond(A)?
Condition number—large means unstable solves.
- float64?
Default for stable dense linear algebra.