Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Module

scipy.linalg

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.

How it works

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.

Syntax

import scipy.linalg

Key points

  • scipy.linalg is the module-level namespace for SciPy's linear-algebra functionality.
  • inv computes a matrix inverse when an explicit inverse is required.
  • solve computes the unknown vector or array in a square linear system.
  • solve_banded targets systems whose coefficient matrix is represented as banded.
  • eig handles both ordinary and generalized eigenvalue problems for square matrices.

Common mistakes

  • Use solve for square systems; it is not the general interface for rectangular least-squares problems.

Example: Solve a linear system

import 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.

When to use it

Linear systems

Compute solutions to square matrix equations in numerical models.

Banded systems

Work with matrices whose nonzero entries lie near the diagonal.

Eigenvalue analysis

Analyze modes, stability, or transformations represented by square matrices.

Matrix operations

Apply standard matrix transformations in scientific computing workflows.

Interview questions

QWhat is scipy.linalg used for?

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.

QHow do you solve a linear system with scipy.linalg?

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.

QWhich scipy.linalg routine handles eigenvalue problems?

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.inv
  • scipy.linalg.solve
  • scipy.linalg.solve_banded
  • scipy.linalg.eig

Source: Linear algebra (scipy.linalg) — SciPy v1.18.0 Manual. Checked 2026-10-15.