To obtain the matrix inverse, use linalg.pinv()
instead of linalg.inv()
linalg.pinv docs: https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.pinv.html linalg.inv docs: https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv.html Andere Ref: https://www.quora.com/What-is-the-difference-between-pinv-and-inv#:~:text=What%20is%20the%20difference%20between%20pinv%20and%20inv%3F,-ad%20b&text=pinv()%20function%20in%20OCTAVE,be%20an%20m*n%20matrix.
When using eigval, eigvec = scipy.linalg.eig()
, the returned eigenvectors are in the columns of eigvec
.
Supposing we want the first eigenvalue & eigenvector pair of a matrix my_matrix
,
import scipy.linalg as la
eigval, eigvec = la.eig(my_matrix)
then we need
eigval_pair1 = eigval[0]
eigvec_pair1 = eigvec[:,0]
and NOT
eigvec_pair1 = eigvec[0]
Recommended Posts