numpy.linalg.eigh#

linalg.eigh(a, UPLO='L')[源代码]#

返回复 Hermitian(共轭对称)或实对称矩阵的特征值和特征向量.

返回两个对象,一个包含 a 的特征值的一维数组,以及一个二维正方形数组或矩阵(取决于输入类型),其中包含相应的特征向量(在列中).

参数:
a(…, M, M) array

要计算其特征值和特征向量的 Hermitian 或实对称矩阵.

UPLO{‘L’, ‘U’}, optional

指定计算使用的是 a 的下三角部分(‘L’,默认)还是上三角部分(‘U’).无论此值如何,为了保持 Hermitian 矩阵的概念,计算中只会考虑对角线的实部.因此,对角线的虚部将始终被视为零.

返回:
具有以下属性的 namedtuple:
eigenvalues(…, M) ndarray

按升序排列的特征值,每个特征值根据其重数重复.

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

eigenvectors[:, i] 是对应于特征值 eigenvalues[i] 的归一化特征向量.如果 a 是矩阵对象,将返回一个矩阵对象.

提出:
LinAlgError

如果特征值计算不收敛.

参见

eigvalsh

实对称或复 Hermitian(共轭对称)数组的特征值.

eig

非对称数组的特征值和右特征向量.

eigvals

非对称数组的特征值.

scipy.linalg.eigh

SciPy 中类似的函数(但也解决了广义特征值问题).

注释

广播规则适用,详情请参阅 numpy.linalg 的文档.

特征值/特征向量使用 LAPACK 例程 _syevd , _heevd 计算.

实对称或复 Hermitian 矩阵的特征值始终是实数. [1] 特征向量(列)的数组 eigenvectors 是酉矩阵,且 a , eigenvalueseigenvectors 满足方程 dot(a, eigenvectors[:, i]) = eigenvalues[i] * eigenvectors[:, i] .

参考

[1]

G. Strang, Linear Algebra and Its Applications, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pg. 222.

示例

>>> import numpy as np
>>> from numpy import linalg as LA
>>> a = np.array([[1, -2j], [2j, 5]])
>>> a
array([[ 1.+0.j, -0.-2.j],
       [ 0.+2.j,  5.+0.j]])
>>> eigenvalues, eigenvectors = LA.eigh(a)
>>> eigenvalues
array([0.17157288, 5.82842712])
>>> eigenvectors
array([[-0.92387953+0.j        , -0.38268343+0.j        ], # may vary
       [ 0.        +0.38268343j,  0.        -0.92387953j]])
>>> (np.dot(a, eigenvectors[:, 0]) -
... eigenvalues[0] * eigenvectors[:, 0])  # verify 1st eigenval/vec pair
array([5.55111512e-17+0.0000000e+00j, 0.00000000e+00+1.2490009e-16j])
>>> (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
matrix([[ 1.+0.j, -0.-2.j],
        [ 0.+2.j,  5.+0.j]])
>>> eigenvalues, eigenvectors = LA.eigh(A)
>>> eigenvalues
array([0.17157288, 5.82842712])
>>> eigenvectors
matrix([[-0.92387953+0.j        , -0.38268343+0.j        ], # may vary
        [ 0.        +0.38268343j,  0.        -0.92387953j]])
>>> # demonstrate the 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]])
>>> # with UPLO='L' this is numerically equivalent to using LA.eig() with:
>>> 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
array([1., 6.])
>>> wb
array([6.+0.j, 1.+0.j])
>>> va
array([[-0.4472136 +0.j        , -0.89442719+0.j        ], # may vary
       [ 0.        +0.89442719j,  0.        -0.4472136j ]])
>>> vb
array([[ 0.89442719+0.j       , -0.        +0.4472136j],
       [-0.        +0.4472136j,  0.89442719+0.j       ]])