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

NumPy · Module

np.linalg

numpy.linalg is NumPy's linear algebra namespace for standard matrix and vector computations. Its routines include solving systems, decompositions, eigenvalue calculations, norms, inverses, and matrix products.

How it works

Importing numpy.linalg gives access to NumPy's linear algebra routines. The module provides standard operations such as solving systems, computing inverses and determinants, decompositions, eigenvalues, norms, and matrix products, with implementations relying on BLAS and LAPACK.

Syntax

import numpy.linalg

Parameters

NameTypeDescription
No parameters; this card describes the module namespace rather than one callable.

Returns

No direct return value; importing the module exposes linear algebra functions and routines.

Key points

  • The module implements standard linear algebra algorithms using BLAS and LAPACK-backed routines.
  • Use eig for eigenvalues and right eigenvectors of square matrices.
  • Use eigvalsh for eigenvalues of Hermitian or real symmetric matrices.
  • Use solve to obtain solutions to linear systems.
  • Use inv when an explicit matrix inverse is required.
  • SciPy's linalg module overlaps with NumPy's, while also offering additional linear algebra functionality.

Common mistakes

  • The module supports stacked-array inputs for some operations, but individual function signatures and shape requirements still apply.
  • NumPy's module is not a complete replacement for SciPy's linear algebra submodule; some decompositions and matrix functions are only available in SciPy.

Example: Solve a linear system

import numpy as np

A = np.array([[3.0, 1.0], [1.0, 2.0]])
b = np.array([9.0, 8.0])
x = np.linalg.solve(A, b)
print(x)  # [2. 3.]

Solves the square linear system A @ x = b.

When to use it

Linear systems

Solve equations of the form A @ x = b.

Spectral analysis

Analyze matrix structure through eigenvalues and eigenvectors.

Matrix decompositions

Factor matrices or compute singular values for numerical analysis.

Matrix operations

Calculate inverses, determinants, norms, and products.

  • numpy.linalg.eig
  • numpy.linalg.eigvalsh
  • numpy.linalg.solve
  • numpy.linalg.inv
  • numpy.linalg.svd
  • numpy.linalg.trace
  • numpy.linalg.matmul

Source: Linear algebra. Checked 2026-10-15.