我要评分
获取效率
正确性
完整性
易理解

linalg.eigvalsh

Description

Compute the eigenvalues of a complex Hermitian or real symmetric matrix.

Main difference from eigh: The eigenvectors are not computed.

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.

Examples

>>> import numpy as np
>>> a = np.array([[1, -2j], [2j, 5]])
>>> np.linalg.eigvalsh(a)
array([0.17157288, 5.82842712])
>>> 
>>> 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]])
>>> 
>>> wa = np.linalg.eigvalsh(a)
>>> wa
array([1., 6.])
>>> wb = np.linalg.eigvalsh(b)
>>> wb
array([1., 6.])
>>> wb = np.linalg.eigvals(b)
>>> wb
array([6.+0.j, 1.+0.j])
>>>