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.
9
votes
Check out stackoverflow.com/questions/12672408/…
- emeth
That is exactly what I want to do, but in python.
- Andrew Latham
2 Answers
11
votes
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)
You will see that eigvecs is a complex ndarray, so perhaps you have to use eigvecs.real...
In the same module you have eigvalsh() which would probably perform faster for your case, but it doesn't return the eigenvectors.
9
votes
Have you seen scipy.linalg.eig? From the documentation:
Solve an ordinary or generalized eigenvalue problem of a square matrix.
This method have optional parameter b:
scipy.linalg.eig(a, b=None, ...
b : (M, M) array_like, optional Right-hand side matrix in a generalized eigenvalue problem. Default is None, identity matrix is assumed.