You are viewing an older version (2.4.3).Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / numpy / linalg / eigh

_ArrayFunctionDispatcher

numpy.linalg:eigh

source: /numpy/linalg/_linalg.py:1515

Signature

def eigh(a, UPLO = L)

Summary

Return the eigenvalues and eigenvectors of a complex Hermitian (conjugate symmetric) or a real symmetric matrix.

Extended Summary

Returns two objects, a 1-D array containing the eigenvalues of a, and a 2-D square array or matrix (depending on the input type) of the corresponding eigenvectors (in columns).

Parameters

a : (..., M, M) array

Hermitian or real symmetric matrices whose eigenvalues and eigenvectors are to be computed.

UPLO : {'L', 'U'}, optional

Specifies whether the calculation is done with the lower triangular part of a ('L', default) or the upper triangular part ('U'). Irrespective of this value only the real parts of the diagonal will be considered in the computation to preserve the notion of a Hermitian matrix. It therefore follows that the imaginary part of the diagonal will always be treated as zero.

Returns

: A namedtuple with the following attributes:
eigenvalues : (..., M) ndarray

The eigenvalues in ascending order, each repeated according to its multiplicity.

eigenvectors : {(..., M, M) ndarray, (..., M, M) matrix}

The column eigenvectors[:, i] is the normalized eigenvector corresponding to the eigenvalue eigenvalues[i]. Will return a matrix object if a is a matrix object.

Raises

: LinAlgError

If the eigenvalue computation does not converge.

Notes

Broadcasting rules apply, see the numpy.linalg documentation for details.

The eigenvalues/eigenvectors are computed using LAPACK routines _syevd, _heevd.

The eigenvalues of real symmetric or complex Hermitian matrices are always real. [1] The array eigenvalues of (column) eigenvectors is unitary and a, eigenvalues, and eigenvectors satisfy the equations dot(a, eigenvectors[:, i]) = eigenvalues[i] * eigenvectors[:, i].

Examples

import numpy as np
from numpy import linalg as LA
a = np.array([[1, -2j], [2j, 5]])
a
eigenvalues, eigenvectors = LA.eigh(a)
eigenvalues
✓
array([0.17157288, 5.82842712])
eigenvectors
✗
array([[-0.92387953+0.j        , -0.38268343+0.j        ],
       [ 0.        +0.38268343j,  0.        -0.92387953j]])
(np.dot(a, eigenvectors[:, 0]) -
eigenvalues[0] * eigenvectors[:, 0])  # verify 1st eigenval/vec pair
(np.dot(a, eigenvectors[:, 1]) -
eigenvalues[1] * eigenvectors[:, 1])  # verify 2nd eigenval/vec pair
✓
array([0.+0.j, 0.+0.j])
A = np.matrix(a) # what happens if input is a matrix object
A
eigenvalues, eigenvectors = LA.eigh(A)
eigenvalues
✓
array([0.17157288, 5.82842712])
eigenvectors
✗
matrix([[-0.92387953+0.j        , -0.38268343+0.j        ],
        [ 0.        +0.38268343j,  0.        -0.92387953j]])
a = np.array([[5+2j, 9-2j], [0+2j, 2-1j]])
a
b = np.array([[5.+0.j, 0.-2.j], [0.+2.j, 2.-0.j]])
✓
b
✗
array([[5.+0.j, 0.-2.j],
       [0.+2.j, 2.-0.j]])
wa, va = LA.eigh(a)
wb, vb = LA.eig(b)
wa
wb
✓
array([6.+0.j, 1.+0.j])
va
✗
array([[-0.4472136 +0.j        , -0.89442719+0.j        ],
       [ 0.        +0.89442719j,  0.        -0.4472136j ]])
vb
✓
array([[ 0.89442719+0.j       , -0.        +0.4472136j],
       [-0.        +0.4472136j,  0.89442719+0.j       ]])

See also

eig

eigenvalues and right eigenvectors for non-symmetric arrays.

eigvals

eigenvalues of non-symmetric arrays.

eigvalsh

eigenvalues of real symmetric or complex Hermitian (conjugate symmetric) arrays.

scipy.linalg.eigh

Similar function in SciPy (but also solves the generalized eigenvalue problem).

Aliases

  • numpy.linalg.eigh

Referenced by