Search code examples
pythonnumpyeigenvalueeigenvector

Eigen decomposition of two square matrix in python


In matlab we have option to find eigen decomposition of two matrix, no matter there product is symmetric or non symmetric such as

A = [1 3; 4 9];
B = [4 7; 9 16];
[Vec,Val]=eig(A,B)

Vectors are

`[-1,-1;0.54,0.85]`  

and value are

[-3.79,0;0,0.79]

I have checked in python numpy.linalg but there is no such option. All of the eig variation accept only one parameters. Is there way to deal with this in python


Solution

  • You can use scipy.linalg.eig:

    from scipy import linalg
    linalg.eig(A, B)
    

    where A = [[1,3],[4,9]] and B = [[4,7], [9,16]] are your two matrices.