S1-09 · 基础S1-09 · Foundation

矩阵 · 让多组向量排成行列Matrix · Arrange Several Vectors in Rows and Columns

rows × columns = samples × features

矩阵是按行列排列的一组数,可同时保存多组向量或一次变换。Transformer 中大量计算都以矩阵发生。A matrix is a rectangular arrangement of numbers that can hold several vectors or one transformation. Much of Transformer computation happens in matrices.

01 · 三件商品,三个特征01 · Three products, three features

怎样把三条向量放在一起,还能一眼找到“第 2 条样本的价格”?How can three vectors stay together while “the price of sample 2” remains easy to locate?

023×3 矩阵编辑台3×3 Matrix Editor

单元格联动型Cell-linked view
Rows
3
样本向量sample vectors
Columns
3
特征位置feature positions
当前值Active value
2.0
Mij

03矩阵里的 4 个位置概念Four Position Concepts in a Matrix

行与列各有职责Rows and columns have roles
PART 01

Row

这里一行保存一条商品样本向量。Here, one row stores one product sample vector.

PART 02

Column

这里一列收集所有样本的同一个特征。Here, one column collects the same feature across samples.

PART 03

单元格Cell

Mij 是第 i 行、第 j 列交叉处的一个标量。Mij is one scalar at row i and column j.

PART 04

形状Shape

3×3 先写行数再写列数,说明一共有 9 个位置。3×3 lists rows before columns and contains nine positions.

04最小机制:用两个索引找到一个标量Minimal Mechanism: Two Indices Find One Scalar

Mij
M ∈ R3×3, Mij = row i ∩ column j
在上方点任一输入框:高亮行确定哪条样本,高亮列确定哪个特征,交叉点就是当前值。Focus any input above: the highlighted row selects a sample, the column selects a feature, and their intersection is the value.
选择行 iChoose row i定位一条向量Locate one vector
选择列 jChoose column j定位同一特征Locate one feature
读取 MijRead Mij得到一个标量Get one scalar

05边界实验:让第二行少一个格Boundary Test: Remove One Cell from Row Two

主动制造失败Create a failure

制造不齐整的“矩阵”Create a ragged “matrix”

点击后删掉第 2 条样本的价格。第二行只剩两个位置,列就无法保持同一含义。Remove price from sample 2. Its row now has two positions and the columns no longer preserve one shared meaning.

尚未执行。矩阵必须保持每行同样多的列。Not run yet. Every matrix row must keep the same number of columns.
一行可以随意多一个或少一个值。A row may freely contain more or fewer values. → ✓ 矩阵是矩形,每行列数必须一致。A matrix is rectangular; every row has equal length.
3×5 表示 3 列、5 行。3×5 means three columns and five rows. → ✓ 形状约定先行后列。Shape notation lists rows before columns.
行列只是排版,没有含义。Rows and columns are only visual layout. → ✓ 索引含义决定数值如何被解释和计算。Index roles determine interpretation and computation.
06 · 一句话带走06 · One line to keep

矩阵是按行列排列的一组数,可同时保存多组向量;编辑一个单元格,就能用高亮行找到样本、用高亮列找到特征。A matrix arranges numbers in rows and columns and can store several vectors. Edit one cell: its row identifies the sample and its column the feature.