Guozhen AIGlobal AI field notes and model intelligence

English translation

Create a 2-row, 3-column matrix

Published:

Category: Linear Algebra

Read time: 4 min

Reads: 0

Lesson #4Views are counted together with the original Chinese articleImages are preserved from the source page

Concept Map: Definition and Representation of Matrices

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.

Matrix Definition & Representation Checklist

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:

Matrix Definition & Representation Judgment Card

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.

A=(a11a12a1na21a22a2nam1am2amn)A = \begin{pmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{pmatrix}

Types of Matrices

Based on the number of rows and columns, matrices fall into several categories:

  1. Row matrix: A matrix with only one row, of shape 1 × n.
  2. Column matrix: A matrix with only one column, of shape m × 1.
  3. Square matrix: A matrix with equal numbers of rows and columns, of shape n × n.
  4. Zero matrix: A matrix whose all entries are zero.
  5. 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:

  1. Text notation:

    A = [[a11, a12, ..., a1n],
         [a21, a22, ..., a2n],
         ...,
         [am1, am2, ..., amn]]
    
  2. 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)

Application Review Card: Vectors and Matrices — Definition and Representation of Matrices

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.

Application Check Card: Vectors and Matrices — Definition and Representation of Matrices

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.

Linear Algebra Implementation Card

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

Keep reading from here

Browse English site

Reader Messages

Reader messages

Questions, corrections, extra sources, or hands-on results can be left here. No login is required.

Max 800 characters

To reduce spam, each message is checked for length, link count, and posting frequency.

0/800

Messages

0 messages
Loading messages...