Linear systems
Compute solutions to square matrix equations in numerical models.
SciPy · Module
scipy.linalg is SciPy's module for linear algebra. Its documented routines cover matrix inverses, linear systems, banded systems, and ordinary or generalized eigenvalue problems.
The scipy.linalg module provides linear-algebra routines for matrix operations, decompositions, eigenvalue problems, and linear systems. Use its functions with NumPy arrays; for example, solve computes x from the square-system relation A @ x = b.
import scipy.linalgimport numpy as np
from scipy import linalg
A = np.array([[3.0, 1.0], [1.0, 2.0]])
b = np.array([9.0, 8.0])
x = linalg.solve(A, b)
print(x)Solves a square linear system and prints the vector whose matrix product with A equals b.
Compute solutions to square matrix equations in numerical models.
Work with matrices whose nonzero entries lie near the diagonal.
Analyze modes, stability, or transformations represented by square matrices.
Apply standard matrix transformations in scientific computing workflows.
scipy.linalg is SciPy's collection of linear-algebra functions. It includes operations such as matrix inversion, linear-system solving, banded-system solving, and eigenvalue computation.
Follow-up: How would you solve a banded system efficiently? Use solve_banded with the band structure and its compact banded representation.
linalg.solve computes the unknown x in A @ x = b when A is square. The right-hand side b may represent one or multiple right-hand sides, provided its dimensions match the system.
Follow-up: When is solve_banded preferable? When the coefficient matrix has a known band structure, because the routine accepts that structure explicitly.
The module includes eig for ordinary or generalized eigenvalue problems of square matrices. For a generalized problem, provide the second matrix as b in eig(a, b).
Follow-up: What additional result can an eigenvalue routine provide? eig can compute left and right eigenvectors when the corresponding options are requested.
scipy.linalg.invscipy.linalg.solvescipy.linalg.solve_bandedscipy.linalg.eig