Rate This Document
Findability
Accuracy
Completeness
Readability

linalg.eigh

Description

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

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

Mandatory Input Parameters

Parameter

Type

Description

a

(…, M, M) array

Hermitian or real symmetric matrices

Optional Input Parameters

Parameter

Type

Default Value

Description

UPLO

{'L', 'U'},

'L'

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

Return Value

Parameter

Type

Description

w

(…, M) ndarray

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

v

{(…, M, M) ndarray, (…, M, M) matrix}

The column v[:, i] is the normalized eigenvector corresponding to the eigenvalue w[i]. A matrix object is returned if a is a matrix object.

Examples

>>> import numpy as np
>>> # Vector input
>>> a = np.array([[1,-2j], [2j, 5]])
>>> a
array([[ 1.+0.j, -0.-2.j],
       [ 0.+2.j,  5.+0.j]])
>>> w, v = np.linalg.eigh(a)
>>> w, v
(array([0.17157288, 5.82842712]), array([[-0.92387953-0.j        , -0.38268343+0.j        ],
       [ 0.        +0.38268343j,  0.        -0.92387953j]]))
>>> 
>>> np.dot(a, v[:, 0]) - w[0] * v[:, 0]
array([5.55111512e-17+0.0000000e+00j, 0.00000000e+00+1.2490009e-16j])
>>> np.dot(a, v[:, 1]) - w[1] * v[:, 1]
array([0.+0.j, 0.+0.j])
>>> 
>>> # Matrix input
>>> A = np.matrix(a)
>>> A
matrix([[ 1.+0.j, -0.-2.j],
        [ 0.+2.j,  5.+0.j]])
>>> w, v = np.linalg.eigh(A)
>>> w; v
array([0.17157288, 5.82842712])
matrix([[-0.92387953-0.j        , -0.38268343+0.j        ],
        [ 0.        +0.38268343j,  0.        -0.92387953j]])
>>> 
>>> # Treatment of the imaginary part of the diagonal
>>> a = np.array([[5+2j, 9-2j], [0+2j, 2-1j]])
>>> a
array([[5.+2.j, 9.-2.j],
       [0.+2.j, 2.-1.j]])
>>> 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]])
>>> 
>>> np.linalg.eigh(a)
(array([1., 6.]), array([[-0.4472136 -0.j        , -0.89442719+0.j        ],
       [ 0.        +0.89442719j,  0.        -0.4472136j ]]))
>>> 
>>> np.linalg.eigh(b)
(array([1., 6.]), array([[-0.4472136 -0.j        , -0.89442719+0.j        ],
       [ 0.        +0.89442719j,  0.        -0.4472136j ]]))
>>>