4.1.1 线性代数路线图:数据是向量,批量是矩阵
线性代数是 AI 表示数据和变换数据的语言。不要从背证明开始,先看每个对象在代码里做什么。
先看地图

本小章流向是:

| 概念 | 在 AI 里的第一层意思 |
|---|---|
| 向量 | 一个对象写成一串数字 |
| 矩阵 | 多个向量叠在一起,或表示一种变换 |
| 点积 | 对应位置相乘后求和 |
| 矩阵乘法 | 一次做很多个点积 |
| 特征值/特征向量 | 重要方向,是理解 PCA 的入口 |
跑最小闭环
创建 linear_algebra_first_loop.py,安装 numpy 后运行。
import numpy as np
student = np.array([90, 85, 92])
students = np.array(
[
[90, 85, 92],
[70, 88, 75],
[95, 91, 89],
]
)
weights = np.array([0.4, 0.2, 0.4])
single_score = student @ weights
all_scores = students @ weights
print("student_vector:", student)
print("matrix_shape:", students.shape)
print("single_score:", round(single_score, 2))
print("all_scores:", all_scores.round(2))
预期输出:
student_vector: [90 85 92]
matrix_shape: (3, 3)
single_score: 89.8
all_scores: [89.8 75.6 91.8]
如果误用 * 而不是 @,得到的是逐元素相乘,不是加权得分。这是新手最值得先分清的地方。
按这个顺序学
| 顺序 | 阅读 | 先抓住什么 |
|---|---|---|
| 1 | 4.1.2 向量 | 对象 -> 向量、长度、点积、余弦相似度 |
| 2 | 4.1.3 矩阵 | 批量数据、矩阵乘法、X @ W + b |
| 3 | 4.1.4 特征值与特征向量 | 特殊方向、PCA 直觉 |
| 4 | 4.1.5 向量空间 | 基、维度、线性变换 |
通过标准
能解释为什么一个样本是向量、一批样本是矩阵、@ 在做什么,以及这些概念为什么会出现在 RAG 相似度、PCA 和神经网络层里,就算通过。