Previously, I wrote as a test to find eigenvalues and eigenvectors using python, but I forgot, so I rewrote it for review.
EigenValue.py
#encoding:UTF-8
import numpy
import scipy.linalg
def EigenValue():
#Set how many eigenvalues are to be calculated
hi = 2
lo = 0
#Make a suitable matrix
A = numpy.matrix([[1,2,3],[4,5,6],[7,8,9]])
#Calculate eigenvalues and eigenvectors
eigen_value,eigen_vector = scipy.linalg.eigh(A,eigvals=(lo,hi))
#Sort in descending order of eigenvalues
eigen_id = numpy.argsort(eigen_value)[::-1]
eigen_value = eigen_value[:,eigen_id]
eigen_vector = eigen_vector[:,eigen_id]
print eigen_value
print eigen_vector
if __name__=="__main__":
EigenValue()
Parameters
http://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eigh.html
Recommended Posts