解决Numpy中的广义特征值问题 [英] Solve Generalized Eigenvalue Problem in Numpy
问题描述
我正在寻求解决以下类型的问题:Aw = xBw
其中x
是标量(特征值),w
是特征向量,并且A
和B
是对称的平方小数矩阵尺寸相等.如果A
和B
是d x d
,我应该能够找到d
x/w对.我将如何在numpy中解决此问题?我正在寻找Scipy文档,却找不到想要的东西.
I am looking to solve a problem of the type: Aw = xBw
where x
is a scalar (eigenvalue), w
is an eigenvector, and A
and B
are symmetric, square numpy matrices of equal dimension. I should be able to find d
x/w pairs if A
and B
are d x d
. How would I solve this in numpy? I was looking in the Scipy docs and not finding anything like what I wanted.
推荐答案
对于对称密集矩阵,可以使用scipy.linalg.eigh()
解决此广义特征值问题:
For symmetric dense matrices, you can use scipy.linalg.eigh()
to solve this generalized eigenvalue problem:
from scipy.linalg import eigh
eigvals, eigvecs = eigh(A, B, eigvals_only=False)
您会看到eigvecs
是复杂的ndarray
,所以也许您必须使用eigvecs.real
...
You will see that eigvecs
is a complex ndarray
, so perhaps you have to use eigvecs.real
...
在同一模块中,您有eigvalsh()
可能会针对您的情况更快地执行,但不会返回特征向量.
In the same module you have eigvalsh()
which would probably perform faster for your case, but it doesn't return the eigenvectors.
这篇关于解决Numpy中的广义特征值问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!