Try to calculate Trace in Python

What I want to do: Check out the Trace proposition of linear algebra

{\rm Tr}(PAP^{-1})={\rm Tr}(A)

What is Trace? (For the time being, review)

$ n $ Square matrix $ A = (a_ {ij}) $ plus the sum of diagonal components:

{\rm Tr}(A):=\sum_{i=1}^na_{ii} 

(Sample) Matrix definition

A=\left(
\begin{matrix}
1 & 2 \\
3 & 4 
\end{matrix}
\right),
P=\left(
\begin{matrix}
2 & 3 \\
4 & 5 
\end{matrix}
\right)

will do. In the implementation it looks like this:

> import numpy as np
> A = np.array([[1,2],[3,4]])
> P = np.array([[2,3],[4,5]])

For the time being, the contents of ck

> A 
array([[1, 2],
       [3, 4]])
> P
array([[2, 3],
       [4, 5]])

Ck the determinant of P

If the determinant is 0, there is no inverse matrix.

> np.linalg.det(P)
-2.0

→ It looks okay!

Trace calculation

> np.trace(np.dot(np.dot(P,A),inv_P))
5.0
> np.trace(A)
5

Well, the result is that it seems to be so, but w

Of course, this cannot be a mathematical proof, but as a practice material for Python.

Recommended Posts

Try to calculate Trace in Python
Try to calculate a statistical problem in Python
Try to calculate RPN in Python (for beginners)
Try logging in to qiita with Python
Try gRPC in Python
Try 9 slices in Python
First steps to try Google CloudVision in Python
3.14 π day, so try to output in Python
Try auto to automatically price Enums in Python 3.6
Calculate mW <-> dBm in Python
To flush stdout in Python
Try to understand Python self
Login to website in Python
Try LINE Notify in Python
Speech to speech in python [text to speech]
Try implementing Yubaba in Python 3
How to develop in Python
Post to Slack in Python
Try to make a Python module in C language
Try to make it using GUI and PyQt in Python
Convert markdown to PDF in Python
How to collect images in Python
Try implementing extension method in python
How to use SQLite in Python
Calculate free-space path loss in Python
Try python
Try using LevelDB in Python (plyvel)
In the python command python points to python3.8
Various ways to calculate the similarity between data in python
Try PLC register access in Python
Try to put data in MongoDB
Try converting cloudmonkey CLI to python3 -1
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
6 ways to string objects in Python
How to use PubChem in Python
Calculate the previous month in Python
How to calculate date with python
Cython to try in the shortest
Add TRACE log level to Python ...?
Try using Leap Motion in Python
How to handle Japanese in Python
Just try to receive a webhook in ngrok and python
An alternative to `pause` in Python
Try to get a list of breaking news threads in Python.
[Cloudian # 9] Try to display the metadata of the object in Python (boto3)
[Cloudian # 2] Try to display the object storage bucket in Python (boto3)
Try to log in to Netflix automatically using python on your PC
How to calculate "xx time" in one shot with Python timedelta
I tried to implement PLSA in Python
Try to reproduce color film with Python
[Introduction to Python] How to use class in Python?
Try using the Wunderlist API in Python
Install Pyaudio to play wave in python
I tried to implement permutation in Python
Method to build Python environment in Xcode 6
How to dynamically define variables in Python
Try using the Kraken API in Python
How to do R chartr () in Python
Try working with binary data in Python