Skip to content

🌐 [translation-sync] [numpy.md] Update np.random → Generator API#65

Open
mmcky wants to merge 2 commits into
mainfrom
translation-sync-2026-05-13T10-46-45-pr-549
Open

🌐 [translation-sync] [numpy.md] Update np.random → Generator API#65
mmcky wants to merge 2 commits into
mainfrom
translation-sync-2026-05-13T10-46-45-pr-549

Conversation

@mmcky
Copy link
Copy Markdown
Contributor

@mmcky mmcky commented May 13, 2026

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.yml

Details

  • Source Language: en
  • Target Language: zh-cn
  • Model: claude-sonnet-4-6

This PR was created automatically by the translation action.

@github-actions
Copy link
Copy Markdown

✅ Translation Quality Review

Verdict: PASS | Model: claude-sonnet-4-6 | Date: 2026-05-13


📝 Translation Quality

Criterion Score
Accuracy 9/10
Fluency 9/10
Terminology 9/10
Formatting 9/10
Overall 9/10

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:

  • Mutability section: '我们在上面已经看到了可变性的例子。' → Consider '我们在前面已经看到了可变性的示例。' for slightly more natural academic phrasing (上面 vs 前面 for textual reference).

  • Making Copies section: '现在 b 是一个独立副本(称为深拷贝)' → The source says 'deep copy' which is correctly rendered as '深拷贝', but consider '深度拷贝' or keep '深拷贝' — both are acceptable; however consistency with standard CS terminology in Chinese ('深拷贝') is fine as-is.

  • Universal Functions section: '并非所有用户自定义函数都会逐元素作用。' → Source says 'Not all user-defined functions will act element-wise.' The translation is accurate, but '用户自定义函数' could be rendered as '用户定义的函数' for slightly more natural Chinese flow.

  • Implicit Multithreading section: '让我们看一个例子来观察这一点。' → Source says 'Let's look at an example to see this in action.' A slightly more idiomatic rendering would be '让我们通过一个例子来直观地感受这一点。' to better capture 'in action'.

  • Exercises (np_ex4): The timer label in the translation uses '广播操作' and 'For 循环操作' which are translations of the English string arguments to qe.Timer(). Since these are string literals in code context that affect runtime output, it may be preferable to keep the original English strings 'Broadcasting operation' and 'For loop operation' to match the source code exactly.


🔍 Diff Quality

Check Status
Scope Correct
Position Correct
Structure Preserved
Heading-map Correct
Overall 10/10

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and numpy.random.uniform usage with Generator-based calls (default_rng, standard_normal, uniform, binomial).
  • Added an optional seed parameter to the DiscreteRV example and stored a per-instance RNG.
  • Updated .translate/state/numpy.md.yml with 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.

Comment thread lectures/numpy.md
@@ -990,7 +980,7 @@ def f(x):
NumPy 函数 `np.where` 提供了一个向量化的替代方案:

```{code-cell} python3
Comment thread lectures/numpy.md
Comment on lines +1247 to 1254
def __init__(self, q, seed=None):
"""
参数 q 是一个 NumPy 数组或类似数组,非负且和为 1
"""
self.q = q
self.Q = cumsum(q)
self.rng = np.random.default_rng(seed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants