Skip to content

Instantly share code, notes, and snippets.

@kyoro1
Created November 2, 2015 11:47
Show Gist options
  • Save kyoro1/a7866c4efc09c92a4308 to your computer and use it in GitHub Desktop.
Save kyoro1/a7866c4efc09c92a4308 to your computer and use it in GitHub Desktop.
PythonでTraceを計算してみる ref: http://qiita.com/kyoro1/items/77b1b7c9634e16f09ee4
{\rm Tr}(PAP^{-1})={\rm Tr}(A)
{\rm Tr}(A):=\sum_{i=1}^na_{ii}
A=\left(
\begin{matrix}
1 & 2 \\
3 & 4
\end{matrix}
\right),
P=\left(
\begin{matrix}
2 & 3 \\
4 & 5
\end{matrix}
\right)
> import numpy as np
> A = np.array([[1,2],[3,4]])
> P = np.array([[2,3],[4,5]])
> A
array([[1, 2],
[3, 4]])
> P
array([[2, 3],
[4, 5]])
> np.linalg.det(P)
-2.0
> np.trace(np.dot(np.dot(P,A),inv_P))
5.0
> np.trace(A)
5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment