Square Matrix
A matrix where the number of rows(m) equals to the number of columns(n).
Main diagonal : The vector of values along the diagonal of the matrix from the top left to the bottom right. ( a 11 , a 22 , a 33 ) (a_{11}, a_{22}, a_{33}) ( a 11 , a 22 , a 33 )
S q u a r e M a t r i x o f o r d e r 3 ; A = [ a 11 a 12 a 13 a 21 a 22 a 23 a 31 a 32 a 33 ] Square\hspace{0.1cm}Matrix\hspace{0.1cm}of\hspace{0.1cm}order\hspace{0.1cm}3;\hspace{0.1cm}A=\begin{bmatrix}
a_{11} \hspace{0.2cm} a_{12} \hspace{0.2cm} a_{13}
\\ a_{21} \hspace{0.2cm} a_{22}\hspace{0.2cm} a_{23}
\\ a_{31} \hspace{0.2cm} a_{32}\hspace{0.2cm} a_{33}
\end{bmatrix} Sq u a re M a t r i x o f or d er 3 ; A = a 11 a 12 a 13 a 21 a 22 a 23 a 31 a 32 a 33 Symmetric Matrix
A type of square matrix where the top-right triangle is the same as the bottom-left triangle.
Note: The axis of symmetry is always the main diagonal.
A = [ 1 2 3 4 5 2 1 2 3 4 3 2 1 2 3 4 3 2 1 2 5 4 3 2 1 ] , A = A T A=\begin{bmatrix}
1 \hspace{0.2cm} 2 \hspace{0.2cm} 3\hspace{0.2cm}4\hspace{0.2cm}5
\\ 2\hspace{0.2cm}1\hspace{0.2cm}2\hspace{0.2cm}3\hspace{0.2cm}4
\\ 3\hspace{0.2cm}2\hspace{0.2cm}1\hspace{0.2cm}2\hspace{0.2cm}3
\\ 4\hspace{0.2cm}3\hspace{0.2cm}2\hspace{0.2cm}1\hspace{0.2cm}2
\\ 5\hspace{0.2cm}4\hspace{0.2cm}3\hspace{0.2cm}2\hspace{0.2cm}1
\end{bmatrix}, A = A^T A = 1 2 3 4 5 2 1 2 3 4 3 2 1 2 3 4 3 2 1 2 5 4 3 2 1 , A = A T Triangular Matrix
A type of square matrix that has values in the upper-right or lower-left triangle and filled with zeros in the rest.
U p p e r T r i a n g u l a r M a t r i x A = [ 1 2 3 0 2 3 0 0 3 ] , L o w e r T r i a n g u l a r M a t r i x B = [ 1 0 0 1 2 0 1 2 3 ] Upper Triangular Matrix A=\begin{bmatrix}
1 \hspace{0.2cm} 2 \hspace{0.2cm} 3
\\ 0 \hspace{0.2cm} 2\hspace{0.2cm} 3
\\ 0 \hspace{0.2cm} 0\hspace{0.2cm} 3
\end{bmatrix},
Lower Triangular Matrix B=\begin{bmatrix}
1 \hspace{0.2cm} 0 \hspace{0.2cm} 0
\\ 1 \hspace{0.2cm} 2\hspace{0.2cm} 0
\\ 1 \hspace{0.2cm} 2\hspace{0.2cm} 3
\end{bmatrix} U pp er T r ian gu l a r M a t r i x A = 1 2 3 0 2 3 0 0 3 , L o w er T r ian gu l a r M a t r i x B = 1 0 0 1 2 0 1 2 3
Copy from numpy import array
from numpy import tril
from numpy import triu
M = array ([[ 1 , 2 , 3 ], [ 1 , 2 , 3 ], [ 1 , 2 , 3 ]])
upper = triu (M)
lower = tril (M)
print (upper)
print (lower)
Copy [[1 2 3]
[0 2 3]
[0 0 3]]
[[1 0 0]
[1 2 0]
[1 2 3]]
Diagonal Matrix
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.
Copy 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)
Copy [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'.
Copy from numpy import identity
I = identity(3)
print(I)
Copy [[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'.
Copy 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)
Copy [[ 1 0]
[ 0 -1]]
[[ 1. 0.]
[-0. -1.]]
[[1 0]
[0 1]]
[[1. 0.]
[0. 1.]]
Link:
- Introduction to Matrix Types in Linear Algebra for Machine Learning