Eigenvalues describe how a square matrix scales particular direction vectors. SciPy exposes LAPACK-backed routines for dense matrix eigenvalue problems, which is useful when checking modal behavior, stability calculations, covariance structure, or another matrix result in Python.

The scipy.linalg.eig() function handles a general square matrix and returns eigenvalues plus right eigenvectors by default. The eigenvector in column i belongs to the eigenvalue at index i, so the direct check is A @ v = w * v for each returned column.

Use scipy.linalg.eigh() instead when the input matrix is real symmetric or complex Hermitian, because that routine is specialized for that structure. A small dense general matrix keeps the eigenvalues, eigenvectors, and residual check visible in one terminal run.

Steps to compute eigenvalues with SciPy:

  1. Create a Python script that defines the matrix and computes its eigenpairs.
    compute_eigenvalues.py
    import numpy as np
    from scipy.linalg import eig
     
     
    A = np.array(
        [
            [4.0, 1.0, -2.0],
            [0.0, 3.0, 1.0],
            [0.0, 0.0, 2.0],
        ]
    )
     
    w, vr = eig(A)
    residuals = np.linalg.norm(A @ vr - vr * w, axis=0)
     
    np.set_printoptions(precision=6, suppress=True)
    print("matrix rows:")
    for row in A:
        print(row)
    print("eigenvalues:", w)
    print("right eigenvectors by row:")
    for row in vr:
        print(row)
    print("residuals:", residuals)
    print("max_residual:", residuals.max())
    print("verified:", bool(np.all(residuals < 1e-10)))

    eig() may return complex-valued eigenvalues even for a real input matrix. The right eigenvectors are stored as columns in vr.

  2. Run the eigenvalue script.
    $ python compute_eigenvalues.py
    matrix rows:
    [ 4.  1. -2.]
    [0. 3. 1.]
    [0. 0. 2.]
    eigenvalues: [4.+0.j 3.+0.j 2.+0.j]
    right eigenvectors by row:
    [ 1.       -0.707107  0.727607]
    [ 0.        0.707107 -0.485071]
    [0.       0.       0.485071]
    residuals: [0. 0. 0.]
    max_residual: 2.220446049250313e-16
    verified: True
  3. Match each eigenvalue to the eigenvector column at the same index.

    The first eigenvalue, 4.+0.j, belongs to the first column of vr. The residual calculation broadcasts w across the columns so each column is checked against its own eigenvalue.

  4. Confirm that the residuals are below the chosen tolerance.

    The max_residual value is near floating-point roundoff, and verified: True confirms every returned pair satisfies A @ v = w * v within 1e-10 for this matrix.