For a general dense matrix, use scipy.linalg.eigvals to get eigenvalues only, or scipy.linalg.eig if you also need eigenvectors. For a real symmetric or complex Hermitian matrix, use scipy.linalg.eigvalsh or scipy.linalg.eigh. If a sparse symmetric or Hermitian matrix has many dimensions and you need only a few eigenpairs, consider scipy.sparse.linalg.eigsh.
Choose the SciPy routine that matches your matrix
The main decision is whether the matrix has a structure-specific property and whether you need eigenvectors. SciPy’s linear algebra reference lists these and other specialized solvers.
As an Amazon Associate I earn from qualifying purchases.
| Task | Routine | Key behavior |
|---|---|---|
| Eigenvalues of a general dense matrix | scipy.linalg.eigvals(a) |
Eigenvalue order is unspecified. |
| Eigenvalues and eigenvectors of a general dense matrix | scipy.linalg.eig(a) |
Returns right eigenvectors by default; left eigenvectors are optional. |
| Eigenvalues of a dense real-symmetric or complex-Hermitian matrix | scipy.linalg.eigvalsh(a) |
Assumes symmetry or Hermitian structure; returns values in ascending order. |
| Eigenvalues and eigenvectors of a dense real-symmetric or complex-Hermitian matrix | scipy.linalg.eigh(a) |
Assumes symmetry or Hermitian structure; can select part of the spectrum. |
| A limited number of eigenpairs from a sparse symmetric or Hermitian matrix | scipy.sparse.linalg.eigsh(A, k=...) |
Requires k < N, where N is the matrix dimension. |
Compute eigenvalues of a general dense matrix
Use eigvals when the matrix may be nonsymmetric or non-Hermitian and you do not need eigenvectors. Use eig when you need eigenvectors as well. These general routines support ordinary and generalized eigenvalue problems; SciPy describes eigvals as computing eigenvalues from either kind of problem.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesimport numpy as np
from scipy.linalg import eigvals, eig
A = np.array([[1.0, 2.0],
[3.0, 4.0]])
values = eigvals(A)
values, right_vectors = eig(A)
The returned eigenvalue order from eigvals is not specified, so sort the values yourself if your application needs a particular ordering. eig returns right eigenvectors by default; it can also return left eigenvectors. The routine normalizes right eigenvectors, while its documentation says left eigenvectors are not normalized.
#1 Best Overall
For generalized problems, eigvals(a, b) computes eigenvalues for the pair of matrices. Its homogeneous_eigvals=True option returns numerator/denominator coordinates rather than direct ratios, which the API identifies as useful when a ratio could overflow or underflow.
Use the symmetric or Hermitian routines only when the structure is valid
A real symmetric matrix equals its transpose; a complex Hermitian matrix equals its conjugate transpose. For these matrices, eigvalsh returns eigenvalues only, while eigh returns eigenvalues and eigenvectors by default. The eigvalsh reference describes it as the eigenvalue-only shorthand for eigh(..., eigvals_only=True).
Rank #2
from scipy.linalg import eigvalsh, eigh
# A must actually be symmetric (or Hermitian for complex data).
values = eigvalsh(A)
values, vectors = eigh(A)
These routines assume the required structure; they do not verify that the input satisfies it. If the matrix is not symmetric or Hermitian, they can produce incorrect results without raising an error. Choose eig or eigvals when that assumption is not justified. The symmetric/Hermitian eigenvalues are returned in ascending order.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Generalized symmetric/Hermitian problems
eigh(a, b) solves the default generalized problem a @ v = w * b @ v. For this routine, b must be positive definite. Its type parameter selects among three supported formulations. The API also supports selecting a subset of eigenvalues by index or value; for a generalized subset problem, its documented compatible driver is gvx.
Get a few eigenpairs from a sparse matrix
For a sparse real-symmetric or complex-Hermitian matrix, scipy.sparse.linalg.eigsh is intended for finding a limited number of eigenvalues and eigenvectors rather than computing the full spectrum. Set k to the number of eigenpairs requested; it must be less than the matrix dimension N. Consult the eigsh API reference for its iterative options and parameter details.
There is a documented nuance for complex Hermitian input: eigsh routes the computation through eigs and returns the real parts of the resulting eigenvalues. Do not treat this sparse routine as interchangeable with the dense solvers or assume it computes all eigenvalues.
Handle input checks and convergence deliberately
The dense routines expose check_finite. Setting it to False may improve performance, but SciPy warns that NaN or infinity in the inputs can then lead to crashes or non-termination. Leave the check enabled unless the data has already been validated and the trade-off is acceptable.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteEigenvalue calculations can fail to converge; the dense API documents LinAlgError for such failures, and sparse iterative solvers have their own algorithmic parameters and behavior. No routine guarantees convergence for every input. If a calculation fails, inspect the matrix and the chosen method rather than assuming a different function name alone will resolve it.
Best Value
The dense eig, eigvals, eigh, and eigvalsh references also describe support for arrays with leading batch dimensions. The eigh and eigvalsh references note that zero-size batches are unsupported.
When a specialized solver is a better fit
If your matrix is banded or tridiagonal, SciPy’s linear algebra index lists specialized eigenvalue solvers for those structures. Use them when the matrix genuinely has that form; for an ordinary dense general matrix, use the general routines above.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →




