The number 1 has a special property in arithmetic: any number multiplied by 1 remains unchanged. For example, 5×1=5. This number is called the multiplicative identity. Matrix algebra has its own version of this idea, which is called the identity matrix.
The identity matrix, usually denoted as I, is a square matrix (it has the same number of rows and columns) with ones on the main diagonal and zeros everywhere else. The main diagonal runs from the top-left corner to the bottom-right.
Here are the identity matrices for a 2x2 and a 3x3 matrix:
I2=[1001] I3=100010001The subscript, like the 2 in I2, indicates the size of the matrix. Often, the size is implied by the context, so we just write I.
The defining feature of the identity matrix is that when you multiply any matrix A by it, you get A back, unchanged. The multiplication must be valid, meaning the dimensions have to align. For any n×m matrix A:
AIm=A InA=ALet's see this in action with a 2x2 matrix. Suppose we have the matrix A:
A=[2435]When we multiply A by the 2x2 identity matrix I2:
AI=[2435][1001]=[(2⋅1+3⋅0)(4⋅1+5⋅0)(2⋅0+3⋅1)(4⋅0+5⋅1)]=[2435]As you can see, the result is the original matrix A.
So, how does this help us solve the main problem of this chapter, Ax=b?
Think back to how you solve a simple algebraic equation like 5x=10. You isolate x by multiplying both sides by the reciprocal of 5, which is 51. This turns the coefficient of x into 1:
(51⋅5)x=51⋅10Which simplifies to:
1⋅x=2The identity matrix I plays the role of the number '1' in matrix equations. Our goal in solving Ax=b is to find a way to isolate the vector x. We can't "divide" by a matrix, but we can multiply by a special matrix called the inverse (which we'll cover in the next section) to achieve a similar result. The process will look something like this:
A−1Ax=A−1bWhere the product A−1A results in the identity matrix I:
Ix=A−1bAnd since Ix=x, we are left with the solution:
x=A−1bThe identity matrix is the destination we are trying to reach on one side of the equation to find our solution.
NumPy makes it simple to create identity matrices. You can use the np.identity() function, which takes a single integer argument to specify the size.
import numpy as np
# Create a 3x3 identity matrix
I_3 = np.identity(3)
print("A 3x3 identity matrix:")
print(I_3)
# Create a 5x5 identity matrix
I_5 = np.identity(5)
print("\nA 5x5 identity matrix:")
print(I_5)
Let's use NumPy to verify the multiplicative identity property. We'll create a matrix A and multiply it by I. In NumPy, the @ operator is used for matrix multiplication.
# Define a 3x2 matrix A
A = np.array([
[8, 1],
[6, 3],
[5, 7]
])
# Create a 2x2 identity matrix for A @ I
I_2 = np.identity(2)
# Perform the multiplication
result = A @ I_2
print("Matrix A:\n", A)
print("\nIdentity matrix I:\n", I_2)
print("\nResult of A @ I:\n", result)
# We can check if the result is identical to the original matrix A
are_equal = np.array_equal(A, result)
print(f"\nIs the result the same as A? {are_equal}")
As the code demonstrates, multiplying A by an identity matrix of the correct size yields A itself. This simple yet powerful matrix is a fundamental tool you will use repeatedly when solving systems of equations.
Was this section helpful?
np.identity() function.© 2026 ApX Machine LearningEngineered with