[PYTHON] Find eigenvalues and eigenvectors

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

Find eigenvalues and eigenvectors
Eigenvalues and eigenvectors: Linear algebra in Python <7>
[Mathematics] Let's visualize what are eigenvalues and eigenvectors
Find the Hermitian matrix and its eigenvalues in Python
Python --Read data from a numeric data file to find the covariance matrix, eigenvalues, and eigenvectors
[Pandas] Find quartiles and detect outliers
Linear Algebra for Programming Chapter 4 (Eigenvalues, Eigenvectors)
Find and check inverse matrix in Python
Find all adjective verbs and their positions
Find it in the procession and edit it