2011年4月15日

Scipy求eigenvalues

簡單的求eigenvalues範例:

  1. #-*-coding:utf-8-*-
  2. '''
  3. Created on 2011/4/15
  4. @author: Hung-Hsin Chen
  5. simple example for solving eigenvalues
  6. '''
  7. import numpy as np
  8. from scipy import linalg
  9.  
  10. #A=[[1 2 3] [4 5 6] [7 8 9]]
  11. A = np.arange(1,10).reshape(3,3)   
  12. eigvals, eigvecs = linalg.eig(A)
  13.  
  14. #eigen vector is column vector
  15. for i in range(0,3):
  16.     print eigvals[i], eigvecs[:,i]
  17.  
  18. #A*X = lambda * X
  19. print np.dot(A, eigvecs[:,0].transpose())
  20. print eigvals[0]*eigvecs[:, 0]