Matrix operations are used in many machine learning algorithms. Linear algebra makes matrix operations fast and easy, especially when training on GPUs.
Transpose
A transpose is a matrix which is formed by turning all the rows of a given matrix into columns and vice-versa represented as A^T.
from numpy import array
A = array([[1, 2], [3, 4], [5, 6]])
C = A.T
print(C)
[[1 3 5]
[2 4 6]]
Inversion
Matrix inversion is a process that finds another matrix that when multiplied with the matrix, results in an identity matrix (1's in main diagonal, zeros everywhere else)represented as AB = BA = I
Note: A square matrix that is not invertible is referred to as singular. The matrix inversion operation is not computed directly, but rather the inverted matrix is discovered through forms of matrix decomposition.
B=A−1,I=10..001..0....00..1
from numpy import array
from numpy import dot
from numpy.linalg import inv
A = array([[4,3], [3,2]])
B = inv(A)
print(B)
product = dot(A,B)
print(product)
[[-2. 3.]
[ 3. -4.]]
[[1. 0.]
[0. 1.]]
Trace
A trace of a square matrix is the sum of the values on the main diagonal of the matrix represented as tr(A)