I used next python code to extract the Eigen matrix (EI) of two mmf matrices texts.
import numpy as np
from numpy import *
from matplotlib.pyplot import *
import re
import scipy.linalg as la
data=loadtxt('matKSMMF.txt',skiprows=8)
s = len (data)
print(s)
n=6567
kmat = [[0 for _ in range(n)] for _ in range(n)]
for x in range (s):
m=data[x:x+1,:]
kmat[int (m[0,0])-1][int (m[0,1])-1]=m[0,2]
K=np.array(kmat)
print (K)
data=loadtxt('matMSMMF.txt',skiprows=8)
s = len (data)
print(s)
n=6567
Mmat = [[0 for _ in range(n)] for _ in range(n)]
for x in range (s):
m=data[x:x+1,:]
Mmat[int (m[0,0])-1][int (m[0,1])-1]=m[0,2]
M=np.array(Mmat)
print (M)
inv_M = np.linalg.inv(M)
print(inv_M)
L= la.eig(inv_M @ K)
print ('Eigen vector matrices is', L)
EI=np.array(L)
print (EI)
Unfortunately, I received the next warnings upon running:
VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
EI=np.array(L)
Traceback (most recent call last):
File "mmf.py", line 30, in <module>
EI=np.array(L)
-ValueError: could not broadcast input array from shape (6567,6567) into shape (6567,)
What is the meaning of such a warning/error? and how can I fix them?
If you want to get the array of eigenvectors you can just do this:
scipy.linalg.eig
returns a list that contains a vector of eigenvalues and an array of eigenvectors