Solve Generalized Eigenvalue Problem in Numpy

For real symmetric or complex Hermitian dense matrices, you can use scipy.linalg.eigh() to solve a generalized eigenvalue problem. To avoid extracting all the eigenvalues you can specify only the desired ones by using subset_by_index:

from scipy.linalg import eigh

eigvals, eigvecs = eigh(A, B, eigvals_only=False, subset_by_index=[0, 1, 2])

One could use eigvals_only=True to obtain only the eigenvalues.


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.