Matrix Operations
Explore fundamental matrix operations such as transpose, inverse, and trace. Understand their mathematical properties and how to compute them using Python's NumPy library to support data science tasks.
Transpose
A transpose of the matrix is another matrix, such that , the row of becomes the column of .
Example
Note: The transpose of a symmetric matrix is the same matrix.
Transpose in NumPy
We can use .T to take the transpose of matrices in NumPy. The following code illustrates its use.
Properties of transpose
- is always symmetric.
- is always symmetric.
- and have the same determinant: . We’ll learn about determinants in a later lesson.
- and have the same rank. We’ll learn rank in a later lesson.
- and have the same set of eigenvalues. We’ll learn about eigenvalues in a later lesson.
The following code verifies some of these properties:
Inverse
The inverse of a square matrix is another matrix, , such that .
Example
If , then .
Note: Not all square matrices have inverses. Some are invertible, and others aren’t.
Inverse in NumPy
We can use .inv() to take the inverse of a square matrix. The following code illustrates its use:
Note: We’ll learn how to compute the inverse of a matrix in a later lesson.
Properties of inverse
- is always a square matrix.
- .
- .
- .
- .
- and have the same eigenvectors.
- The eigenvalues of and are reciprocals of each other.
The following code verifies some of these properties:
Trace
The trace of a square matrix is a scalar value, , which is the sum of the main diagonal elements of the matrix.
Example
If , then .
Trace in NumPy
We can use .trace() to compute the trace of a matrix in NumPy. The following code illustrates its use:
Properties of trace
The following code verifies some of these properties: