23 / 90

第 23 天:矩陣乘法、shape 台帳、轉置與逆矩陣

把矩陣乘法當作線性映射的複合來計算,為每個乘積寫下明確的 (m x k)(k x n) -> m x n shape 台帳,並建立轉置、單位矩陣與逆矩陣的直覺。把每個乘積與模型內部的權重矩陣連結起來。每項活動都在 480 分鐘台帳中記錄預測、觀察、複習與復原。

數學與演算法基礎 480 活躍分鐘(8 小時專注學習)
01 120 分鐘

矩陣乘法即線性映射的複合

僅在記錄預測與觀察證據後才可使用協助。

前置要求

完成第 22 天;若矩陣-向量乘積不熟練,使用列出的復原連結。

學習目標

按行乘列的點積逐項計算矩陣乘積,把 A*B 解釋為『先施加 B、再施加 A』的複合映射,並實證矩陣乘法不可交換。

操作指引

元素 (A*B)_ij 是 A 的第 i 行與 B 的第 j 列的點積。幾何上 (A*B)*x = A*(B*x):乘積矩陣先施加內層映射,所以複合要從右往左讀。複合依賴順序,因此 A*B 與 B*A 一般不相等。

自主實作與記錄

設 A = [[1,2],[3,4]],B = [[0,1],[1,0]](B 交換向量的分量)。計算前先預測兩個乘積:(a) A*B;(b) B*A。二者相等嗎?

獨立掌握標準

正確算出兩個乘積,解釋從右向左的複合讀法,並舉出一個幾何理由說明兩種順序為何不同(先交換再映射 vs 先映射再交換)。

權威來源資源與權利證明

linking 3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions No video, audio, transcript or frame redistribution permitted

Essence of Linear Algebra

作者 / 機構: Grant Sanderson (3Blue1Brown) | 原始出處連結 ↗

對應章節 / 時間戳: Chapter 4: Matrix multiplication as composition

驗證版本與日期: 2016-2023 (Verified: 2026-10-30)

入選理由:

Unequaled geometric and visual intuition for vectors, linear transformations, matrix multiplication, and inverses before tensor operations.

來源前置條件:

High-school coordinate geometry

安全回退方案(離線彈性):

Geometric explanations, worked formulas, and coordinate exercises are fully provided as original lesson text.

對比候選資源與選型分析 (2)
MIT OCW 18.06 Linear Algebra (Prof. Gilbert Strang) ↗ compared_alternative [CC BY-NC-SA 4.0]

Established textbook/lecture approach, strong mathematical rigor alongside 3Blue1Brown visual intuition.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Theoretical determinant-free proof structure is mathematically elegant but less aligned with computational tensor engineering.

linking CC BY-NC-SA 4.0 noncommercial share-alike

18.06 Linear Algebra (Prof. Gilbert Strang)

作者 / 機構: MIT OpenCourseWare (Prof. Gilbert Strang) | 原始出處連結 ↗

對應章節 / 時間戳: Lecture 3: matrix multiplication and its four viewpoints

驗證版本與日期: Spring 2010 (Verified: 2026-10-30)

入選理由:

Established row-picture and column-picture treatment of linear systems, matrix products, and invertibility; rigorous complement to the 3Blue1Brown visual series.

來源前置條件:

High-school algebra and coordinate geometry

安全回退方案(離線彈性):

All row/column-picture derivations and worked examples are written as original lesson text and run offline.

對比候選資源與選型分析 (3)
3Blue1Brown: Essence of Linear Algebra ↗ compared_selected_for_days_22_24 [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

Selected as co-primary: geometric visualizations paired with Strang's algebraic rigor.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Determinant-free theoretical treatment is elegant but further from the computational shape accounting required here.

Immersive Linear Algebra (online interactive book) ↗ compared_rejected_for_days_22_24 [Free online (site terms; no OSI/CC license declared)]

Interactive figures are attractive, but the absence of a declared open license makes rights disposition unclear; kept out of the resource set.

02 120 分鐘

shape 台帳:預測乘積的維度

獨立練習:先記錄預測再核對結果;記錄證據後才可使用協助。

前置要求

完成上一活動;如受阻,使用列出的復原連結。

學習目標

為每個乘積寫書面 shape 台帳:(m x k)(k x n) -> (m x n);內側維度必須匹配,不匹配是要預測的錯誤,而不是死記的規則。

操作指引

寫下兩邊的 shape,檢查內側維度是否一致,然後在計算任何元素之前先預測輸出 shape。同樣的台帳用於模型模組:MLP 把 shape 為 (batch x d_model) 的 X 依次乘以 W1 (d_model x d_ff) 和 W2 (d_ff x d_model)。每個權重矩陣都是模型內部的 2 秩張量。

自主實作與記錄

預測 shape 與數值。(a) C (2x3) = [[1,0,2],[-1,3,1]] 乘 D (3x2) = [[3,1],[2,1],[1,0]]:輸出 shape 是什麼?算出全部四個元素。(b) Transformer MLP 台帳:X (32 x 768) * W1 (768 x 3072),再 * W2 (3072 x 768)。(c) (2x3)(2x3) 合法嗎?

獨立掌握標準

計算前預測每個輸出 shape,精確重現 C*D = [[5,1],[4,2]],並用一個失敗例子說明『內側維度必須匹配』這條規則。

權威來源資源與權利證明

linking CC BY-NC-SA 4.0 noncommercial share-alike

18.06 Linear Algebra (Prof. Gilbert Strang)

作者 / 機構: MIT OpenCourseWare (Prof. Gilbert Strang) | 原始出處連結 ↗

對應章節 / 時間戳: Lecture 3: (m x k)(k x n) -> m x n dimension rule

驗證版本與日期: Spring 2010 (Verified: 2026-10-30)

入選理由:

Established row-picture and column-picture treatment of linear systems, matrix products, and invertibility; rigorous complement to the 3Blue1Brown visual series.

來源前置條件:

High-school algebra and coordinate geometry

安全回退方案(離線彈性):

All row/column-picture derivations and worked examples are written as original lesson text and run offline.

對比候選資源與選型分析 (3)
3Blue1Brown: Essence of Linear Algebra ↗ compared_selected_for_days_22_24 [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

Selected as co-primary: geometric visualizations paired with Strang's algebraic rigor.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Determinant-free theoretical treatment is elegant but further from the computational shape accounting required here.

Immersive Linear Algebra (online interactive book) ↗ compared_rejected_for_days_22_24 [Free online (site terms; no OSI/CC license declared)]

Interactive figures are attractive, but the absence of a declared open license makes rights disposition unclear; kept out of the resource set.

linking BSD 3-Clause License

NumPy Reference: The N-dimensional array (ndarray)

作者 / 機構: NumPy Developers | 原始出處連結 ↗

對應章節 / 時間戳: ndarray.shape semantics and matrix product dimensions

驗證版本與日期: NumPy 2.x documentation (Verified: 2026-10-30)

入選理由:

Primary semantics for ndarray shape, strides, reshape orders, and view-versus-copy behavior used in tensor memory accounting.

來源前置條件:

Basic Python

安全回退方案(離線彈性):

Shape, stride, and memory-ledger exercises are fully explained with local runnable examples.

對比候選資源與選型分析 (2)
PyTorch Documentation: torch.Tensor ↗ compared_alternative [Modified BSD]

Equivalent tensor semantics in the framework used later in the curriculum; NumPy reference selected to keep Days 22-24 dependency-free.

NumPy User Guide: Broadcasting ↗ compared_selected_for_days_22_24 [BSD 3-Clause License]

Selected as co-primary for Day 24: the broadcasting rules page pairs with the ndarray attribute reference.

03 120 分鐘

轉置、單位矩陣與逆矩陣的直覺

僅在記錄預測與觀察證據後才可使用協助。

前置要求

完成上一活動;如受阻,使用列出的復原連結。

學習目標

把轉置當作沿對角線的鏡像使用,掌握 (A*B)^T = B^T * A^T;把單位矩陣 I 當作『什麼都不做』的映射;把 A^-1 讀作撤銷 A 的映射——只有當 A 沒有壓扁任何方向時才存在。

操作指引

轉置交換行與列:(A^T)_ij = A_ji,乘積取轉置時順序反轉。單位矩陣 I 滿足 I*x = x。逆矩陣 A^-1 滿足 A*A^-1 = I。零空間非平凡的矩陣會把某個方向壓成零,任何逆矩陣都無法復原它;對 2x2 矩陣,det = ad - bc = 0 就是這種壓扁的訊號。

自主實作與記錄

(a) 用上一活動的 C*D = [[5,1],[4,2]],預測 (C*D)^T 並驗證它等於 D^T * C^T。(b) 對 A = [[2,1],[1,1]],透過計算 A * A^-1 驗證 A^-1 = [[1,-1],[-1,2]]。(c) S = [[1,2],[2,4]]:求 det(S),並找出使 S*x = 0 的非零 x;S 可逆嗎?

獨立掌握標準

逐元素驗證 A * A^-1 = I,用數值實證轉置的乘積規則,並用 S*(2,-1) = 0 解釋『奇異就是某個方向被摧毀』。

權威來源資源與權利證明

linking 3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions No video, audio, transcript or frame redistribution permitted

Essence of Linear Algebra

作者 / 機構: Grant Sanderson (3Blue1Brown) | 原始出處連結 ↗

對應章節 / 時間戳: Chapters 5-6: determinants and inverse matrices

驗證版本與日期: 2016-2023 (Verified: 2026-10-30)

入選理由:

Unequaled geometric and visual intuition for vectors, linear transformations, matrix multiplication, and inverses before tensor operations.

來源前置條件:

High-school coordinate geometry

安全回退方案(離線彈性):

Geometric explanations, worked formulas, and coordinate exercises are fully provided as original lesson text.

對比候選資源與選型分析 (2)
MIT OCW 18.06 Linear Algebra (Prof. Gilbert Strang) ↗ compared_alternative [CC BY-NC-SA 4.0]

Established textbook/lecture approach, strong mathematical rigor alongside 3Blue1Brown visual intuition.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Theoretical determinant-free proof structure is mathematically elegant but less aligned with computational tensor engineering.

linking CC BY-NC-SA 4.0 noncommercial share-alike

18.06 Linear Algebra (Prof. Gilbert Strang)

作者 / 機構: MIT OpenCourseWare (Prof. Gilbert Strang) | 原始出處連結 ↗

對應章節 / 時間戳: Lecture 3: inverses and transposes; Lecture 4: factorization

驗證版本與日期: Spring 2010 (Verified: 2026-10-30)

入選理由:

Established row-picture and column-picture treatment of linear systems, matrix products, and invertibility; rigorous complement to the 3Blue1Brown visual series.

來源前置條件:

High-school algebra and coordinate geometry

安全回退方案(離線彈性):

All row/column-picture derivations and worked examples are written as original lesson text and run offline.

對比候選資源與選型分析 (3)
3Blue1Brown: Essence of Linear Algebra ↗ compared_selected_for_days_22_24 [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

Selected as co-primary: geometric visualizations paired with Strang's algebraic rigor.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Determinant-free theoretical treatment is elegant but further from the computational shape accounting required here.

Immersive Linear Algebra (online interactive book) ↗ compared_rejected_for_days_22_24 [Free online (site terms; no OSI/CC license declared)]

Interactive figures are attractive, but the absence of a declared open license makes rights disposition unclear; kept out of the resource set.

04 120 分鐘

獨立掌握:乘積、shape 與可逆性

獨立掌握檢查(無 AI 協助)。

前置要求

完成上一活動;如受阻,使用列出的復原連結。

學習目標

在無協助下計算 2x2 乘積、預測注意力 shape 台帳、判定給定矩陣是否可逆;任何錯誤都要寫出復原筆記。

操作指引

閉卷進行:先預測,再計算,後比較。乘之前先記錄每個 shape。若結果出乎意料,記錄誤用了哪條規則並記下復原連結。

自主實作與記錄

任務:(a) P = [[1,1],[0,1]]、M = [[2,0],[1,1]] 時的 P*M;(b) 注意力台帳:Q (8 x 64) 乘 K^T(K 為 (8 x 64)),再過 softmax,再乘 V (8 x 64):預測每個輸出 shape;(c) [[2,4],[1,2]] 可逆嗎?

獨立掌握標準

所有預測經無協助驗證;用自己的話寫出 (8x8) 注意力分數 shape 與奇異性論證,並附完整 shape 台帳。

權威來源資源與權利證明

linking CC BY-NC-SA 4.0 noncommercial share-alike

18.06 Linear Algebra (Prof. Gilbert Strang)

作者 / 機構: MIT OpenCourseWare (Prof. Gilbert Strang) | 原始出處連結 ↗

對應章節 / 時間戳: Lecture 1-3 problem sets on products and inverses

驗證版本與日期: Spring 2010 (Verified: 2026-10-30)

入選理由:

Established row-picture and column-picture treatment of linear systems, matrix products, and invertibility; rigorous complement to the 3Blue1Brown visual series.

來源前置條件:

High-school algebra and coordinate geometry

安全回退方案(離線彈性):

All row/column-picture derivations and worked examples are written as original lesson text and run offline.

對比候選資源與選型分析 (3)
3Blue1Brown: Essence of Linear Algebra ↗ compared_selected_for_days_22_24 [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

Selected as co-primary: geometric visualizations paired with Strang's algebraic rigor.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Determinant-free theoretical treatment is elegant but further from the computational shape accounting required here.

Immersive Linear Algebra (online interactive book) ↗ compared_rejected_for_days_22_24 [Free online (site terms; no OSI/CC license declared)]

Interactive figures are attractive, but the absence of a declared open license makes rights disposition unclear; kept out of the resource set.

linking 3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions No video, audio, transcript or frame redistribution permitted

Essence of Linear Algebra

作者 / 機構: Grant Sanderson (3Blue1Brown) | 原始出處連結 ↗

對應章節 / 時間戳: Chapters 4-6 review

驗證版本與日期: 2016-2023 (Verified: 2026-10-30)

入選理由:

Unequaled geometric and visual intuition for vectors, linear transformations, matrix multiplication, and inverses before tensor operations.

來源前置條件:

High-school coordinate geometry

安全回退方案(離線彈性):

Geometric explanations, worked formulas, and coordinate exercises are fully provided as original lesson text.

對比候選資源與選型分析 (2)
MIT OCW 18.06 Linear Algebra (Prof. Gilbert Strang) ↗ compared_alternative [CC BY-NC-SA 4.0]

Established textbook/lecture approach, strong mathematical rigor alongside 3Blue1Brown visual intuition.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Theoretical determinant-free proof structure is mathematically elegant but less aligned with computational tensor engineering.