Numpy: Generalized Eigenvalue Problem

I am looking for a solution to a problem like: Aw = xBw where x is a scalar (eigenvalue), w is an eigenvector, and A and B are symmetric numpy square matrices of equal size. I have to find d x / w pairs if A and B are dxd . How can I solve this in numpy? I looked in the Scipy docs and did not find anything like what I wanted.

+6
source share
2 answers

It seems you need 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 maybe you need to use eigvecs.real ...

In the same module, you have eigvalsh() , which will probably work faster for your case, but it does not return eigenvectors.

+7
source

Have you seen scipy.linalg.eig ? From the doc:

Solve the ordinary or generalized eigenvalue problem of a square matrix.

This method has an 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. 
+6
source

Source: https://habr.com/ru/post/972233/


All Articles