6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

固有値・固有ベクトルを求める

Last updated at Posted at 2015-01-28

以前、pythonを使って固有値・固有ベクトルを求めることをテストとして記述したのだが忘れてしまったので復習のため記述しなおしてみた。

EigenValue.py
#encoding:UTF-8

import numpy
import scipy.linalg


def EigenValue():
    
    #固有値をいくつ求めるかを設定する
    hi = 2
    lo = 0

    #適当な行列を作る 
    A = numpy.matrix([[1,2,3],[4,5,6],[7,8,9]])

    #固有値、固有ベクトルを計算
    eigen_value,eigen_vector = scipy.linalg.eigh(A,eigvals=(lo,hi))

    #固有値の大きい順番で並べ替える
    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()

パラメータ

http://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eigh.html

6
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?