🌐 [translation-sync] [numpy.md] Update np.random → Generator API#65
🌐 [translation-sync] [numpy.md] Update np.random → Generator API#65mmcky wants to merge 2 commits into
Conversation
✅ Translation Quality ReviewVerdict: PASS | Model: claude-sonnet-4-6 | Date: 2026-05-13 📝 Translation Quality
Summary: The translation of the modified sections (Mutability, Making Copies, Universal Functions, Sub-packages, Implicit Multithreading, and Exercises) is of high quality. Technical accuracy is excellent, terminology follows established conventions, and the MyST formatting is properly preserved. Minor issues include a few instances where more idiomatic Chinese phrasing could be used, and one case where English string literals in code (timer labels) have been translated, which may affect output consistency with the source. Overall, this is a professional and reliable translation. Technical terminology is consistently and correctly translated throughout all modified sections, including 'ufuncs'→'通用函数', 'vectorized functions'→'向量化函数', 'deep copy'→'深拷贝', 'multithreading'→'多线程'. The Mutability and Making Copies sections accurately convey the conceptual explanation about Python's reference model and memory behavior, preserving the nuance of the original. Mathematical expressions, code blocks, MyST directives, and cross-references are all properly preserved in the modified sections. The Exercises section translations are clear and accurate, with exercise instructions and hints rendered in natural academic Chinese. The Sub-packages section correctly translates all technical content including random variable generation and linear algebra subpackage descriptions. Suggestions:
🔍 Diff Quality
Summary: The translation correctly mirrors all source changes, updating deprecated np.random.randn/seed usage to rng.standard_normal/default_rng patterns, updating the Sub-packages section text and random variable generation code, and preserving all document structure and translation metadata. This review was generated automatically by action-translation review mode. |
There was a problem hiding this comment.
Pull request overview
This automated translation-sync PR updates the Chinese NumPy lecture to use NumPy’s newer np.random.Generator API (via default_rng) instead of legacy np.random.* functions, and refreshes the translation state metadata to match the upstream source PR.
Changes:
- Replaced
np.random.randn,np.random.seed, andnumpy.random.uniformusage withGenerator-based calls (default_rng,standard_normal,uniform,binomial). - Added an optional
seedparameter to theDiscreteRVexample and stored a per-instance RNG. - Updated
.translate/state/numpy.md.ymlwith the new upstream source SHA, sync date, mode, and tool version.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
lectures/numpy.md |
Migrates examples to np.random.default_rng() / Generator methods and adjusts related narrative/formatting. |
.translate/state/numpy.md.yml |
Updates translation-sync metadata to track the new upstream commit and sync run. |
Comments suppressed due to low confidence (2)
lectures/numpy.md:1063
- 该示例依赖外部作用域里的
rng,但本小节没有初始化随机数生成器。为保证示例可独立运行,建议在此代码单元中加入rng = np.random.default_rng()(必要时可给定 seed 以便复现)。
我们已经看到了如何使用 NumPy 的 [随机 `Generator`](https://numpy.org/doc/stable/reference/random/generator.html#random-generator) 生成随机变量。
```{code-cell} python3
z = rng.standard_normal(10000) # 生成标准正态随机数
y = rng.binomial(10, 0.5, size=1000) # 从 Bin(10, 0.5) 中抽取 1000 个样本
y.mean()
lectures/numpy.md:1107
- 这一段用
rng.standard_normal生成随机矩阵,但rng在本节没有定义;如果读者单独运行该示例会失败。建议在该代码单元前/内添加rng = np.random.default_rng()以消除对前文状态的隐式依赖。
```{code-cell} python3
n = 20
m = 1000
for i in range(n):
X = rng.standard_normal((m, m))
λ = np.linalg.eigvals(X)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -990,7 +980,7 @@ def f(x): | |||
| NumPy 函数 `np.where` 提供了一个向量化的替代方案: | |||
|
|
|||
| ```{code-cell} python3 | |||
| def __init__(self, q, seed=None): | ||
| """ | ||
| 参数 q 是一个 NumPy 数组或类似数组,非负且和为 1 | ||
| """ | ||
| self.q = q | ||
| self.Q = cumsum(q) | ||
| self.rng = np.random.default_rng(seed) | ||
|
|
Automated Translation Sync
This PR contains automated translations from QuantEcon/lecture-python-programming.
Source PR
#549 - [numpy.md] Update np.random → Generator API
Files Updated
lectures/numpy.md.translate/state/numpy.md.ymlDetails
This PR was created automatically by the translation action.