NumPy Notes

Shape Manipulating reshape 可以把 NumPy 的 reshape 操作想象成一个先摊平, 再重铺的过程 核心思想: 无论你原来的数组是什么形状,也无论你想要变成什么新形状,reshape 都会(概念上)做两步: 摊平 (Flattening): 一行一行地把整个数组中的元素读出来, 形成一维数组 重铺 (Refilling): 再根据 reshape 后的形状填满一行一行地填满整个数组 import numpy as np a = np.array([[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]) # Flatten a_flat = a.reshape(1, 12) print("Flattened array: ", a_flat) # Refill a_refilled = a_flat.reshape(3, 4) print("Refilled array: ", a_refilled) transpose 高维转置的本质是重新安排数组的索引顺序,而不是传统意义上的"矩阵转置" concatenate & stack concatenate: 沿着现有的轨道/维度进行延伸或对接 concatenate 是将多个数组沿着一个已经存在的维度(轴,axis)拼接起来。结果数组的维度数量通常与输入数组的维度数量相同 工作方式: 你需要指定一个 axis 参数,告诉 NumPy 沿着哪个维度进行拼接。 除了要拼接的那个维度之外,其他所有维度的大小必须完全相同。 就像你要把两列火车车厢接起来,它们的高度和宽度得匹配,只有长度可以不同(然后加起来) A = np.array([[1, 2], [3, 4]]) B = np.array([[5, 6]]) # 注意:B 也是二维的,才能在 axis=0 上与 A 匹配列数 np.concatenate((A, B), axis=0) # 结果: # [[1, 2], # [3, 4], # [5, 6]] (行数增加了,列数不变) A = np.array([[1, 2], [3, 4]]) C = np.array([[5, 6], [7, 8]]) np.concatenate((A, C), axis=1) # 结果: # [[1, 2, 5, 6], # [3, 4, 7, 8]] (列数增加了,行数不变) stack: 将多个独立的层叠放起来,形成一个新的维度 ...

May 26, 2025 · Last updated on August 1, 2025 · 5 min · KKKZOZ

Build a Large Language Model (From Scratch) Reading Note

Chapter 1 GPT是自回归模型:像GPT这样的解码器式模型,它们生成文本的方式是一次预测一个词 (one word at a time)。也就是说,它会根据已经生成的词语序列来预测下一个最可能出现的词语,然后将这个预测到的词语加入到序列中,再进行下一步的预测,如此循环。这种依赖于自身先前输出进行下一步预测的特性,使得这类模型被称为“自回归模型”(Autoregressive model)。 Chapter 2 Word2Vec trained neural network architecture to generate word embeddings by predicting the context of a word given the target word or vice versa. The main idea behind Word2Vec is that words that appear in similar contexts tend to have similar meanings. LLMs commonly produce their own embeddings that are part of the input layer and are updated during training. The advantage of optimizing the embeddings as part of the LLM training instead of using Word2Vec is that the embeddings are optimized to the specific task and data at hand. ...

May 20, 2025 · Last updated on August 18, 2025 · 9 min · KKKZOZ

Useful Websites

Some useful websites for references. Daily Life Picture Compressor NanoReview – tech comparison and ratings Convert anything to anything - PrintFriendly GPU Database | TechPowerUp Programming Code Image Generator OpenJDK Docker Proxy 钱多多 API GPU calculator Text to ASCII Art Generator (TAAG) Models.dev — An open-source database of AI models Ecosyste.ms: Issues CheatSheets.zip - Ultimate Cheat for Developers Obsidian Vimrc Copilot Info Plans for GitHub Copilot Requests in GitHub Copilot Monitoring your Copilot usage and entitlements GitHub Copilot features Copilot ask, edit, and agent modes: What they do and when to use them - The GitHub Blog Gemini API Info Gemini Developer API Pricing | Gemini API | Google AI for Developers Rate limits | Gemini API | Google AI for Developers

May 19, 2025 · Last updated on September 12, 2025 · 1 min · KKKZOZ

Common Golang Mistakes

Irregular updates Go Gotcha: math/rand Thread Safety Isn’t Universal Ran into a subtle trap with Go’s math/rand package regarding concurrency. It’s easy to assume all random generation is thread-safe, but that’s not quite right. The Key Difference: rand.Intn() (Package Level): Thread-safe! Uses a global source with an internal mutex. Good for most concurrent uses. myRand.Intn() (Method on *rand.Rand): NOT thread-safe by default! If you create your own *rand.Rand instance (myRand) and share it between goroutines, calling its methods concurrently without your own locking will cause data races. Example I Encountered: ...

April 23, 2025 · Last updated on August 3, 2025 · 1 min · KKKZOZ

Effective MacOS Shortcuts

Summarize the various keyboard shortcuts I am currently using. Key Mapping Map Caps Lock to Hyper key (Using Karabiner) System Wide Open Apps Use Karabiner Open apps with Hyper key: Hyper + Q: Open QQ Hyper + W: Open WeChat Hyper + E: Open Browser (Easy to press) Hyper + A: Open Alacritty Hyper + S: Open Sublime Hyper + D: Open VSCode (Easy to press) Hyper + Z: Open Zotero Hyper + X: Open Typora (Easy to press) Hyper + C: Open VSCode (Easy to press) Hyper + P: Open PowerPoint Hyper + L: Open Excel Hyper + H: Hide Current Window (Combo: Hyper + A, then + H to peek new messages) Open Utilities Option + W: Bob Translate Option + .: Raycast Note Cmd + Space: Trigger Raycast Option + Space: To be determined Hyper + Space: Open Raycast AI Chat Option + Cmd + Space: Open Spotlight Ctrl + Option + Space: Trigger Emoji Search (Raycast) Windows Utilities Option + H: First Two Thirds ...

April 19, 2025 · Last updated on August 3, 2025 · 3 min · KKKZOZ

Dev Operations

This blog post will primarily document and summarize some issues I usually encounter in Unix environments, including but not limited to command line and Git operations. ![NOTE] UPDATE Contents related to git have been integrated to Git Essentials. Remote Address 很常见很弱智的一个错误, 但就是架不住偶尔会犯一次 在开启 http server 之类的操作时, 如果填的地址是 localhost:9000, 那么只有本机可以访问 如果想在其他主机上访问, 需要填为 :9000 Bash Shell Shell 分类: 登录 (Login) vs 非登录 (Non-Login): 登录 Shell: 通常是你通过验证身份(输入用户名和密码,或使用 SSH 密钥)后第一个启动的 Shell。比如: 直接在物理控制台登录 通过 ssh user@host 远程登录 使用 su - 或 sudo -i 切换用户(注意那个 - 或 -i 很关键,它们表示模拟一次完整的登录) 非登录 Shell: 不是通过上述登录过程直接启动的 Shell。比如: 在图形界面中已经登录后,打开一个新的终端窗口 在 Shell 中执行一个脚本 (bash script.sh) 在已有 Shell 中再启动一个新的 Shell (bash) 交互式 (Interactive) vs 非交互式 (Non-Interactive): 交互式 Shell: Shell 的标准输入、输出和错误都连接到终端,并且你可以在其中输入命令并看到输出。简单说,就是你正在与之交互的 Shell 非交互式 Shell: Shell 不是直接连接到终端进行交互的。最常见的例子是运行 Shell 脚本。Shell 从脚本文件读取命令,并将输出(如果未重定向)发送到标准输出,但它不期望用户实时输入命令 根据这两种分类, 可以组合出三种常见的 shell 类型: ...

April 17, 2025 · Last updated on August 10, 2025 · 9 min · KKKZOZ

jj-vcs Tutorial

Basic Operations Interact with Changes jj-vcs treats each unit of work as a “change.” You can interact with changes through commands that create, switch, and record them. # Create a change whose ancestor is <change-id> # This operation will check out to the new change # You can disable the behavior by add "--no-edit" jj new <change-id> # Update the change description or other metadata jj desc -m "<message>" # Update current change's description and create a new change on top jj commit -m "<message>" # "Check out" the change jj edit <change-id> Show Repo Status # Show the current change jj st # Show the current change's log jj log Workflows The Squash Workflow If you are familiar and comfortable with git’s index, you can try this workflow to get yourself started with jj-vcs. ...

April 4, 2025 · Last updated on August 10, 2025 · 8 min · KKKZOZ

Chrome Plugin Recommendations

This article records several of my favorite Chrome extensions. PrintFriendly1 Make web pages printer-friendly and convert them to PDFs. Easily remove ads and navigation, and customize what you print or PDF. Convert web pages to PDF, and ignore some non-essential elements, suitable for processing technical blogs and similar content before putting them into Zotero. Wikiwand2 AI-driven wiki aggregator created to enhance user experience on Wikipedia by streamlining knowledge consumption. ...

April 1, 2025 · Last updated on August 4, 2025 · 2 min · KKKZOZ