English translation
Create a 2-row, 3-column matrix
There are two most practical ways to understand a matrix:
- as a table of data, or
- as a transformer that moves vectors to new positions.
I always write down the matrix shape explicitly first. Confusing rows and columns will lead to errors in subsequent matrix multiplication and model input.
In the previous article, we explored the definition and representation of vectors, gaining insight into their importance in machine learning and data science. In this article, we introduce the definition and representation of matrices—a foundational concept in linear algebra, closely related to vectors, and essential for building more complex computations such as neural networks.
Definition of a Matrix
A matrix is a rectangular array of elements arranged in m rows and n columns. It is conventionally denoted by uppercase letters such as A, B, C, etc. Each element in the matrix is written as a_{ij}, where i denotes the row index and j denotes the column index. For example, an m × n matrix can be expressed as:
When learning the definition of a matrix, begin by clarifying what rows, columns, and individual elements represent. A matrix may serve as a data table, or as a linear transformation—its meaning depends on context.
Types of Matrices
Based on the number of rows and columns, matrices fall into several categories:
- Row matrix: A matrix with only one row, of shape
1 × n. - Column matrix: A matrix with only one column, of shape
m × 1. - Square matrix: A matrix with equal numbers of rows and columns, of shape
n × n. - Zero matrix: A matrix whose all entries are zero.
- Identity matrix: A square matrix with ones on the main diagonal and zeros elsewhere; commonly denoted
I_n.
Matrix Notation
Matrices are commonly represented in two formats:
-
Text notation:
A = [[a11, a12, ..., a1n], [a21, a22, ..., a2n], ..., [am1, am2, ..., amn]] -
LaTeX notation:
As shown above, LaTeX provides an elegant way to typeset matrices.
Matrix Elements
Matrix elements can be of any data type—integers, floating-point numbers, or even more complex structures. In practice, we primarily work with floating-point matrices, since they are used to represent diverse data such as images, audio, and more.
Case Study: Matrices in Image Processing
In image processing, a color image is typically represented as a 3D matrix. For instance, an RGB image of width W and height H is stored as an H × W × 3 matrix, where the third dimension (3) corresponds to the red, green, and blue color channels. Each entry represents the intensity value of a channel (commonly ranging from 0 to 255).
We can manipulate matrices using Python’s NumPy library. Here's a simple example:
import numpy as np
# Create a 2-row, 3-column matrix
A = np.array([[1, 2, 3],
[4, 5, 6]])
print("Matrix A:")
print(A)
# Create a 2 × 2 identity matrix
I = np.eye(2)
print("Identity matrix I:")
print(I)
Matrix Dimensions and Shape
A matrix’s dimensionality is determined by its number of rows and columns. An m × n matrix has m rows and n columns. Its shape is a tuple, conventionally written as (number_of_rows, number_of_columns). In Python, NumPy makes it easy to retrieve this information:
print("Shape of matrix A:", A.shape) # Output: (2, 3)
By this point, you can consolidate “Vectors and Matrices — Definition and Representation of Matrices” into a review table: first clarify the core narrative, then verify understanding with a small task.
After reading “Vectors and Matrices — Definition and Representation of Matrices”, try walking through a small concrete example end-to-end, then assess which steps you can already perform independently.
Summary
In this article, we introduced the fundamental concepts, types, notations, and real-world applications of matrices. Matrices form the backbone of many machine learning algorithms and data analysis techniques. Understanding their properties and operations lays a solid foundation for your deeper study of vector and matrix operations.
Before reading “Vectors and Matrices — Definition and Representation of Matrices”, use the accompanying diagram to confirm the central thread; after reading, check which steps you can execute directly—and which still require supplemental material.
In the next article, we’ll delve into vector and matrix operations, exploring how matrices enable various linear transformations and computations. Stay tuned for this series—we’re building the essential linear algebra knowledge you need for AI.
Continue