ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

Linear Algebra Fundamentals for Machine Learning
Chapter 1: The Building Blocks: Scalars, Vectors, and Matrices
Why Linear Algebra for Machine Learning?
Scalars: The Simplest Objects
Vectors: Points in Space
Matrices: Organizing Data in Grids
Setting Up Your Python Environment
Hands-On Practical: Creating Vectors and Matrices with NumPy
Quiz for Chapter 1
Chapter 2: Working with Vectors
Vector Addition and Subtraction
Scalar Multiplication
The Dot Product
Vector Norms: Measuring Length
Orthogonal Vectors
Hands-On Practical: Vector Operations in NumPy
Quiz for Chapter 2
Chapter 3: Working with Matrices
Matrix Addition and Subtraction
Matrix-Scalar Multiplication
Matrix-Vector Multiplication
Matrix-Matrix Multiplication
The Matrix Transpose
Special Types of Matrices
Hands-On Practical: Matrix Operations in NumPy
Quiz for Chapter 3
Chapter 4: Systems of Linear Equations
Representing Equations in Matrix Form (Ax = b)
The Identity Matrix
The Matrix Inverse
Determinants and Invertibility
Singular vs. Non-Singular Matrices
Hands-On Practical: Solving Systems with NumPy
Quiz for Chapter 4
Chapter 5: Eigenvalues and Eigenvectors
Matrices as Linear Transformations
Defining Eigenvalues and Eigenvectors
Geometric Interpretation
The Characteristic Equation
Hands-On Practical: Finding Eigenvalues with NumPy
Quiz for Chapter 5
Chapter 6: Connecting to Machine Learning
Data Representation for Models
Linear Regression as a Matrix Problem
Dimensionality Reduction with PCA
Measuring Similarity with Dot Products
Practice: Data Manipulation with NumPy
Quiz for Chapter 6

The Identity Matrix

The number 1 has a special property in arithmetic: any number multiplied by 1 remains unchanged. For example, 5×1=55 \times 1 = 55×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 III, 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]I_2 = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}I2​=[10​01​] I3=[100010001]I_3 = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}I3​=​100​010​001​​

The subscript, like the 2 in I2I_2I2​, indicates the size of the matrix. Often, the size is implied by the context, so we just write III.

The Multiplicative Identity Property

The defining feature of the identity matrix is that when you multiply any matrix AAA by it, you get AAA back, unchanged. The multiplication must be valid, meaning the dimensions have to align. For any n×mn \times mn×m matrix AAA:

AIm=AA I_m = AAIm​=A InA=AI_n A = AIn​A=A

Let's see this in action with a 2x2 matrix. Suppose we have the matrix AAA:

A=[2345]A = \begin{bmatrix} 2 & 3 \\ 4 & 5 \end{bmatrix}A=[24​35​]

When we multiply AAA by the 2x2 identity matrix I2I_2I2​:

AI=[2345][1001]=[(2⋅1+3⋅0)(2⋅0+3⋅1)(4⋅1+5⋅0)(4⋅0+5⋅1)]=[2345]A I = \begin{bmatrix} 2 & 3 \\ 4 & 5 \end{bmatrix} \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} = \begin{bmatrix} (2 \cdot 1 + 3 \cdot 0) & (2 \cdot 0 + 3 \cdot 1) \\ (4 \cdot 1 + 5 \cdot 0) & (4 \cdot 0 + 5 \cdot 1) \end{bmatrix} = \begin{bmatrix} 2 & 3 \\ 4 & 5 \end{bmatrix}AI=[24​35​][10​01​]=[(2⋅1+3⋅0)(4⋅1+5⋅0)​(2⋅0+3⋅1)(4⋅0+5⋅1)​]=[24​35​]

As you can see, the result is the original matrix AAA.

Why the Identity Matrix Matters for Solving Equations

So, how does this help us solve the main problem of this chapter, Ax=bAx = bAx=b?

Think back to how you solve a simple algebraic equation like 5x=105x = 105x=10. You isolate xxx by multiplying both sides by the reciprocal of 5, which is 15\frac{1}{5}51​. This turns the coefficient of xxx into 1:

(15⋅5)x=15⋅10(\frac{1}{5} \cdot 5)x = \frac{1}{5} \cdot 10(51​⋅5)x=51​⋅10

Which simplifies to:

1⋅x=21 \cdot x = 21⋅x=2

The identity matrix III plays the role of the number '1' in matrix equations. Our goal in solving Ax=bAx = bAx=b is to find a way to isolate the vector xxx. 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−1bA^{-1} A x = A^{-1} bA−1Ax=A−1b

Where the product A−1AA^{-1} AA−1A results in the identity matrix III:

Ix=A−1bI x = A^{-1} bIx=A−1b

And since Ix=xIx = xIx=x, we are left with the solution:

x=A−1bx = A^{-1} bx=A−1b

The identity matrix is the destination we are trying to reach on one side of the equation to find our solution.

Creating Identity Matrices in NumPy

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.

  • 18.06 Linear Algebra, Spring 2010, Gilbert Strang, 2010 (MIT OpenCourseWare) - This OpenCourseWare course, taught by Gilbert Strang, offers explanations of linear algebra concepts, including the identity matrix and its role.
  • Deep Learning, Ian Goodfellow, Yoshua Bengio, and Aaron Courville, 2016 (MIT Press) - Chapter 2 provides an introduction to linear algebra, explaining concepts like the identity matrix within the context of machine learning.
  • numpy.identity, NumPy Developers, 2024 (NumPy) - Official documentation for generating identity matrices using NumPy's np.identity() function.
  • numpy.matmul, NumPy Developers, 2024 (NumPy Project) - Official documentation detailing matrix multiplication in NumPy, which is used to demonstrate the identity matrix's multiplicative property.

© 2026 ApX Machine Learning