The number 1 has a special property in arithmetic: any number multiplied by 1 remains unchanged. For example, . 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 , 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:
The subscript, like the 2 in , indicates the size of the matrix. Often, the size is implied by the context, so we just write .
The defining feature of the identity matrix is that when you multiply any matrix by it, you get back, unchanged. The multiplication must be valid, meaning the dimensions have to align. For any matrix :
Let's see this in action with a 2x2 matrix. Suppose we have the matrix :
When we multiply by the 2x2 identity matrix :
As you can see, the result is the original matrix .
So, how does this help us solve the main problem of this chapter, ?
Think back to how you solve a simple algebraic equation like . You isolate by multiplying both sides by the reciprocal of 5, which is . This turns the coefficient of into 1:
Which simplifies to:
The identity matrix plays the role of the number '1' in matrix equations. Our goal in solving is to find a way to isolate the vector . 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:
Where the product results in the identity matrix :
And since , we are left with the solution:
The 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 LearningAI Ethics & Transparency•