Friday, March 15, 2019

[tutoral][python] Identity Matrix

The identity matrix [I] for multiplication is a square matrix with a 1 for every element of the principal diagonal (top left to bottom right) and 0 in other position:


It is a special matrix, because when we multiply by it, the original is unchanged:

Let prove A*I = A in Python:
import numpy as np
from scipy import linalg

A = np.array([[13,9,7],[8,7,4],[6,4,0]])
B = np.array([[1,0,0],[0,1,0],[0,0,1]])
print(A.dot(B))
Result:
[[13  9  7]
 [ 8  7  4]
 [ 6  4  0]]
And then I*A = A ?

import numpy as np
from scipy import linalg

A = np.array([[1,0,0],[0,1,0],[0,0,1]])
B = np.array([[13,9,7],[8,7,4],[6,4,0]])
print(A.dot(B))
Result:
[[13  9  7]
 [ 8  7  4]
 [ 6  4  0]]

Orz, the result really same.

Reference :
https://www.mathsisfun.com/algebra/matrix-multiplying.html

No comments :

Post a Comment