Remember how the number 1 works in regular multiplication? If you multiply any number by 1, you get the same number back. For example, 5×1=5 and 1×(−3)=−3. The number 1 is the multiplicative identity for scalar numbers.
Linear algebra has a similar concept for matrix multiplication. There's a special matrix that acts like the number 1. When you multiply another matrix by this special matrix, the original matrix remains unchanged. This special matrix is called the identity matrix, usually denoted by I.
The identity matrix I is always a square matrix, meaning it has the same number of rows and columns. It has a very specific structure:
Here are a few examples:
The 2×2 identity matrix, sometimes written as I2:
I2=[1001]The 3×3 identity matrix, I3:
I3=100010001And so on for larger square matrices. The subscript (like the '2' in I2) indicates the size (n×n) of the square matrix. Often, the size is clear from the context of the matrix multiplication, so we might simply write I.
The fundamental property of the identity matrix I is that for any matrix A, provided the multiplication is defined (the dimensions are compatible), the following holds true:
AI=Aand
IA=ALet's look at a quick example. Consider the matrix A:
A=[2435]Now, let's multiply A by the 2×2 identity matrix I2:
AI2=[2435][1001]If we perform the matrix multiplication step-by-step:
The resulting matrix is:
AI2=[2435]=AYou can perform the multiplication in the other order, I2A, and verify that it also yields A. The identity matrix I serves as the neutral element for matrix multiplication, much like the number 1 does for scalar multiplication.
Let's revisit a simple scalar equation, for instance, 5x=10. How do you solve for x? You multiply both sides by the multiplicative inverse (or reciprocal) of 5, which is 1/5:
(1/5)×5x=(1/5)×10This simplifies because (1/5)×5=1:
1x=2And since 1x is just x:
x=2The critical step was multiplying by the inverse (1/5) to turn the coefficient of x into 1 (the multiplicative identity), which isolated x.
The identity matrix I plays an analogous role when we want to solve matrix equations of the form Ax=b. The goal is often to isolate the vector x. If we could find a special matrix, which we'll call A−1 (read as "A inverse"), that has the property A−1A=I, then we could multiply both sides of the equation Ax=b by this A−1 matrix (from the left):
A−1(Ax)=A−1bUsing the associative property of matrix multiplication, we can regroup the left side:
(A−1A)x=A−1bNow, since we chose A−1 such that A−1A=I:
Ix=A−1bFinally, just as 1x=x, multiplying the identity matrix I by a vector x leaves the vector unchanged (Ix=x):
x=A−1bThis algebraic manipulation shows that if we can find this "inverse" matrix A−1, we have a way to find the solution vector x. The identity matrix I is the cornerstone of this concept, representing the state where the original matrix A's effect has been neutralized, leaving x isolated. We will delve into this inverse matrix A−1 in the next section.
NumPy makes creating identity matrices straightforward with the numpy.eye(n)
function, which generates an n×n identity matrix.
import numpy as np
# Create a 2x2 identity matrix
I2 = np.eye(2)
print("2x2 Identity Matrix:")
print(I2)
# Create a 4x4 identity matrix
I4 = np.eye(4)
print("\n4x4 Identity Matrix:")
print(I4)
# Create a 3x3 identity matrix with integer type
I3_int = np.eye(3, dtype=int)
print("\n3x3 Integer Identity Matrix:")
print(I3_int)
Executing this code will output:
2x2 Identity Matrix:
[[1. 0.]
[0. 1.]]
4x4 Identity Matrix:
[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]
3x3 Integer Identity Matrix:
[[1 0 0]
[0 1 0]
[0 0 1]]
Note that NumPy often uses floating-point numbers by default (e.g., 1.
and 0.
). You can specify the data type using the dtype
argument, as shown in the third example, if you specifically need integers or another type.
With this understanding of the identity matrix and its role analogous to the number 1, we are prepared to explore the matrix inverse, A−1, and how it facilitates solving systems of linear equations.
© 2025 ApX Machine Learning