Find the eigenvalues of a real symmetric matrix in Python

eig.py



# coding=utf-8

#Numerical calculation library(LAPACK)
import numpy as np

#Random number library
import random

#10x10 zero matrix
A = np.zeros((10,10))

#Initialization
for i in range(10):
  for j in range(10):
    rand = random.randint(1,10)
    A[i][j] = rand
    A[j][i] = rand

print 'Computational symmetry matrix'
print A

l,v = np.linalg.eig(A)

print 'eigenvalue'
print l

print 'Eigenvector'
print v

It's really easy to do.

If it is true, the number of loops is redundant at the time of initialization of the real symmetric matrix, so I wanted to implement it as follows, but I gave up because all the diagonal terms became zero.

init



for i in range(10):
  for j in range(i):
    rand = random.randint(1,10)
    if rand == 0:
      ptint 1
    A[i][j] = rand
    A[j][i] = rand

I thought about investigating the cause, but I get angry with Syntax Error, so let's do it again

Numpy has LAPACK built in, but Matlab seems to have LAPACK built in the eigenvalue calculation part.

Recommended Posts

Find the eigenvalues of a real symmetric matrix in Python
[Python] Find the transposed matrix in a comprehension
Find the Hermitian matrix and its eigenvalues in Python
Find out the apparent width of a string in python
Find the rank of a matrix in the XOR world (rank of a matrix on F2)
Get the caller of a function in Python
Make a copy of the list in Python
Find the number of days in a month
Find the divisor of the value entered in python
Find the solution of the nth-order equation in python
Output in the form of a python array
Find the difference in Python
A reminder about the implementation of recommendations in Python
Perform "diagonalization of symmetric matrix A using orthogonal matrix U" in Python (eigenvalue decomposition)
Draw a scatterplot matrix in python
Get the number of specific elements in a python list
Python --Find out number of groups in the regex expression
[Note] Import of a file in the parent directory in Python
Get the index of each element of the confusion matrix in Python
Python --Read data from a numeric data file to find the covariance matrix, eigenvalues, and eigenvectors
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
How to determine the existence of a selenium element in Python
How to check the memory size of a variable in Python
Read the standard output of a subprocess line by line in Python
A function that measures the processing time of a method in python
[Python] A simple function to find the center coordinates of a circle
Get the number of readers of a treatise on Mendeley in Python
Find the intersection of a circle and a straight line (sympy matrix)
Check the behavior of destructor in Python
Display a list of alphabets in Python 3
Run the Python interpreter in a script
The result of installing python in Anaconda
[python] [meta] Is the type of python a type?
The basics of running NoxPlayer in Python
Find and check inverse matrix in Python
The story of blackjack A processing (python)
Get a capture of the entire web page in Selenium Python VBA
If you want a singleton in python, think of the module as a singleton
Check the in-memory bytes of a floating point number float in Python
Test & Debug Tips: Create a file of the specified size in Python
Receive a list of the results of parallel processing in Python with starmap
I made a program to check the size of a file in Python
Output the number of CPU cores in Python
Draw a graph of a quadratic function in Python
[Python] Get the files in a folder with Python
[Python] Sort the list of pathlib.Path in natural sort
Match the distribution of each group in Python
View the result of geometry processing in Python
Rewriting elements in a loop of lists (Python)
Read the output of subprocess.Popen in real time
A note about the python version of python virtualenv
Make a joyplot-like plot of R in python
About the behavior of Model.get_or_create () of peewee in Python
Solving the equation of motion in Python (odeint)
[Python] A rough understanding of the logging module
Get a glimpse of machine learning in Python
Find the geometric mean of n! Using Python
A well-prepared record of data analysis in Python
python xlwings: Find the cell in the last row
How to pass the execution result of a shell command in a list in Python
[Circuit x Python] How to find the transfer function of a circuit using Lcapy