Have you ever wondered why matrix multiplication seems so strange? Today, we'll look at a few examples to understand it better. Then, we’ll write our own matrix multiplication code from scratch using Python. Let’s get started!

Vector-Matrix Multiplication

Let’s start with a basic case: multiplying a matrix by a vector. You’ve probably seen this example before—it's pretty simple. In fact, many textbooks use it to help explain what a matrix is in the first place.

Here, we have a vector $\bf{v}$ and we multiply it by a matrix $A$:

$$ A = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{bmatrix}, \quad \bf{v} = \begin{bmatrix} v_1 \\ v_2 \end{bmatrix} $$

The result of multiplying the matrix by the vector is a new vector $\mathbf{w} = A \mathbf{v}$, and its coordinates $w_1, w_2$ are calculated by the following expressions:

$$ A\bf{v} = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{bmatrix} \cdot \begin{bmatrix} v_1 \\ v_2 \end{bmatrix} = \begin{bmatrix} a_{11}\cdot x + a_{12} \cdot y \\ a_{21} \cdot x + a_{22} \cdot y \end{bmatrix} $$

Geometric Interpretation

This operation transforms the vector $\bf{v}$ into a new vector by applying a linear transformation. The matrix $A$:

To understand this better, consider the standard basis vectors:

$$ A \mathbf{e}_1 = \text{first column of } A, \quad A \mathbf{e}_2 = \text{second column of } A $$

Each basis vector gets transformed by the matrix, forming a new coordinate system. This insight is key to und erstanding matrix by matrix multiplication.

Here is the analogy: Imagine stretching and rotating a rubber band by pulling it in different directions. The original shape changes, but it’s still recognizable. The matrix acts like this transformation, modifying the vector’s direction and length.

General Matrix by Matrix Multiplication Through the Lens of Vector Operations

To truly understand matrix multiplication, let’s not think about matrices as a whole at first. Instead, let’s break it down step by step using operations over a vector.

Consider the multiplication of two matrices $A$ and $B$, but instead of looking at the full structure immediately, let’s introduce a vector $\bf{v}$ and analyze the operation:

$$ AB\bf{v} $$