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

SciPy · Function

linalg.eig

Solves ordinary or generalized eigenvalue problems for square matrices. It returns eigenvalues and, optionally, left and normalized right eigenvectors.

How it works

eig solves the ordinary problem A v = w v or, when b is supplied, the generalized problem A v = w B v. It can return normalized right eigenvectors, optional left eigenvectors, or homogeneous eigenvalue coordinates, while flags control input checking and possible in-place workspace use.

Syntax

scipy.linalg.eig(a, b=None, left=False, right=True, overwrite_a=False, overwrite_b=False, check_finite=True, homogeneous_eigvals=False)

Parameters

NameTypeDescription
a(M, M) array_likeSquare input matrix for the eigenvalue problem.
b(M, M) array_likeOptional right-hand-side square matrix for the generalized problem.
leftbool, optionalWhether to compute left eigenvectors.
rightbool, optionalWhether to compute right eigenvectors.
overwrite_abool, optionalAllow overwriting a when possible to reduce workspace use.
overwrite_bbool, optionalAllow overwriting b when possible to reduce workspace use.
check_finitebool, optionalCheck inputs for finite values before computation.
homogeneous_eigvalsbool, optionalReturn generalized eigenvalues in homogeneous coordinates.

Returns

Depending on left and right, returns the eigenvalues w, optional left eigenvectors vl, and optional normalized right eigenvectors vr; w uses homogeneous coordinates when homogeneous_eigvals=True.

Key points

  • Use eig for square-matrix eigenproblems, either ordinary or generalized.
  • The routine supports eigenvalues together with right eigenvectors, left eigenvectors, or both.
  • Each returned right eigenvector is stored as a column of vr and is normalized.
  • When requested, left eigenvectors are arranged by eigenvalue in columns of vl.
  • Pass b to define the second matrix in the generalized equation.
  • The eigenvalue output normally has one value per matrix dimension; homogeneous output uses a different shape.
  • The left-eigenvector output is conditional on setting left=True.

Common mistakes

  • Left eigenvectors returned with left=True are not normalized, unlike the right eigenvectors.

Example: Compute eigenvalues and right eigenvectors

import numpy as np
from scipy.linalg import eig

A = np.array([[1.0, 2.0], [2.0, 1.0]])
w, vr = eig(A)
print(w)
print(vr)

Computes the eigenvalues and normalized right eigenvectors of a real square matrix.

When to use it

Compute matrix eigenpairs

Analyze a square system's modal behavior.

Handle generalized eigenproblems

Solve A v = w B v for two square matrices.

Compute left eigenvectors

Obtain dual vectors for non-Hermitian matrices.

Use homogeneous eigenvalues

Represent potentially infinite generalized eigenvalues safely.

Interview questions

QWhat problems does scipy.linalg.eig solve?

It solves an ordinary or generalized eigenvalue problem. With only a, it finds w and vectors satisfying A v = w v; with b, it solves A v = w B v.

Follow-up: How are left eigenvectors characterized? They satisfy A.H vl[:, i] = w[i].conj() B.H vl[:, i], and they are returned only when left=True.

QWhat does the default return value contain?

By default, the function returns eigenvalues and normalized right eigenvectors. The eigenvector associated with w[i] is the column vr[:, i].

Follow-up: What changes when right=False? The right-eigenvector array is omitted, so the return structure contains only the requested eigenvalue and left-eigenvector results.

QWhat are b and homogeneous_eigvals used for?

b is the right-hand-side matrix for a generalized problem and must have shape (M, M). homogeneous_eigvals=True instead returns eigenvalues in homogeneous coordinates, represented with an extra leading dimension.

Follow-up: Why use homogeneous coordinates? They allow generalized eigenvalues that may otherwise be infinite to be represented without converting them to ordinary finite scalars.

  • scipy.linalg.eigh
  • scipy.linalg.eigvals
  • scipy.linalg.eigvalsh

Source: eig — SciPy v1.18.0 Manual. Checked 2026-10-15.