在numpy或scipy中求实对称矩阵的实特征向量

2024-05-17 17:31:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个实对称矩阵,有很多退化特征值,我想找到这个矩阵的实值特征向量。我正在努力在numpy或scipy中找到一种方法来为我做到这一点,我尝试过给出复值特征向量。有人知道这个函数是否存在吗?在


Tags: 方法函数numpy矩阵scipy特征值特征向量实值
2条回答

别紧张。在

the docs的帮助下:

import numpy as np
from numpy import linalg as LA
a = np.array([[1, 1j], [-1j, 1]])
w, v = LA.eig(a)
# w are the eigenvalues, v are the eigenvectors
# v.real gives the real-valued parts of the eigenvectors
# v == v.real gives a boolean mask for where the vector equals its own real part
real_eigenvectors = v[v.real == v]

使用^{}或{a2}。这些函数是为对称(或Hermitian)矩阵设计的,对于实对称矩阵,它们应该始终返回实特征值和特征向量。在

例如

In [62]: from numpy.linalg import eigh

In [63]: a
Out[63]: 
array([[ 2.,  1.,  0.,  0.],
       [ 1.,  2.,  0.,  0.],
       [ 0.,  0.,  2.,  1.],
       [ 0.,  0.,  1.,  2.]])

In [64]: vals, vecs = eigh(a)

特征值在vals中,相应的特征向量在vecs的列中:

^{pr2}$

相关问题 更多 >