A matrix where values outside the main diagonal have zero value; often represented as D.
Note: A diagonal matrix does not have to be square.
from numpy import array
from numpy import diag
M = array([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
# extract diagonal vector
d = diag(M)
print(d)
# create diagonal matrix from diagonal vector
D = diag(d)
print(D)
[1 2 3]
[[1 0 0]
[0 2 0]
[0 0 3]]
Identity Matrix
A square matrix that does not change a vector when multiplied; often represented as 'I' or 'In'.
from numpy import identity
I = identity(3)
print(I)
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
Orthogonal Matrix
Recap: Two vectors are orthogonal when their dot product equals zero, called orthonormal.
Orthogonal matrix is a square matrix whose columns and rows are orthonormal unit vectors; i.e perpendicular and also have a length/magnitude of 1. It is often denoted as 'Q'.
from numpy import array
from numpy import dot
from numpy import identity
from numpy.linalg import inv
Q = array([[1, 0], [0, -1]])
transpose = Q.T
inverse = inv(Q)
I = identity(2)
# inverse equivalence
print(transpose)
print(inverse)
# identity equivalence
dotproduct = dot(Q,transpose)
print(dotproduct)
print(I)