Skip to content

🌐 [translation-sync] [python_by_example.md] Update np.random → Generator API#59

Open
mmcky wants to merge 2 commits intomainfrom
translation-sync-2026-04-25T11-41-47-pr-538
Open

🌐 [translation-sync] [python_by_example.md] Update np.random → Generator API#59
mmcky wants to merge 2 commits intomainfrom
translation-sync-2026-04-25T11-41-47-pr-538

Conversation

@mmcky
Copy link
Copy Markdown
Contributor

@mmcky mmcky commented Apr 25, 2026

Automated Translation Sync

This PR contains automated translations from QuantEcon/lecture-python-programming.

Source PR

#538 - [python_by_example.md] Update np.random → Generator API

Files Updated

  • ✏️ lectures/python_by_example.md
  • ✏️ .translate/state/python_by_example.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-04-25


📝 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 is of high quality overall. Technical terminology is accurate and consistent with the reference glossary. The Chinese reads naturally with appropriate academic register. All MyST formatting, LaTeX math, and code blocks are preserved correctly. The main minor issue is a slight semantic ambiguity in the While Loops section regarding the loop termination condition phrasing, but it does not constitute a significant error. The exercise translations are faithful and clear. Technical terminology is consistently and accurately translated throughout the modified sections, including '子包' for 'subpackage', '随机抽取' for 'Random Draws', and '独立同分布' for 'IID'. The While Loops section accurately conveys the loop termination semantics and preserves all code blocks and inline code references intact. The Exercises section maintains all mathematical notation, LaTeX equations, and exercise/solution directives correctly. The For Loop section explanation is clear and natural in Chinese, preserving the pedagogical intent of the original with appropriate academic register. Code comments within changed sections (e.g., '# 空列表', '# while 循环的终止条件') are appropriately translated, enhancing readability for Chinese learners. The Version 1 section correctly integrates the i18n font setup code while preserving the original program logic explanation.

Suggestions:

  • While Loops section: '直到条件(i < ts_length)被满足' → '直到条件(i < ts_length)不再满足' — The English says 'until the condition is satisfied' but semantically the while loop runs WHILE the condition is true and stops when it becomes false; the current translation could be misread as the loop stopping when the condition first becomes true, which is the correct behavior but the phrasing '被满足' (is satisfied) is ambiguous. A clearer phrasing would be '只要条件(i < ts_length)成立就持续执行' to match the while loop semantics more precisely.

  • Random Draws section: '接下来两行生成图形。' — The English source says 'The next two lines genererate the plot.' (with a typo in the source). The translation is accurate, but note the source typo 'genererate' was silently corrected, which is appropriate. No change needed.

  • Exercises section (pbe_ex2): '从练习一的解答出发' — The English says 'Starting with your solution to exercise 1'. The translation '练习一' uses Chinese numeral which is consistent with the heading '版本一', but the exercise label is 'pbe_ex1' suggesting it could also be rendered as '练习 1' for consistency with mathematical notation style used elsewhere in the document. Minor style consideration.

  • A Version with a For Loop section: The comment in the code cell was translated from # empty list to # 空列表, which is correct. However, the explanation text references '语句 # 空列表 是一个注释' but the English references '# empty list'. Since code comments are translated in the code block, the body text reference should also reflect the translated comment. This is handled correctly in the translation.


🔍 Diff Quality

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

Summary: The translation target document correctly mirrors all source changes, with code cells updated to use the new RNG API (np.random.default_rng() / rng.standard_normal() / rng.uniform()) in the same positions, while preserving all Chinese translations, document structure, and frontmatter heading-map metadata unchanged.


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

Automated translation sync that updates the zh-cn python_by_example lecture to use NumPy’s Generator API (default_rng() / standard_normal() / uniform()) instead of legacy np.random.* helpers, along with updating the translation state metadata.

Changes:

  • Replace np.random.randn(...) with rng = np.random.default_rng() + rng.standard_normal(...) across examples/solutions.
  • Replace np.random.uniform() with rng.uniform() in the Monte Carlo π exercise solution.
  • Update translation sync state (source-sha, synced-at, mode, tool-version).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lectures/python_by_example.md Updates random-number generation examples to the Generator API and adjusts surrounding explanatory text/formatting.
.translate/state/python_by_example.md.yml Updates translation sync metadata (source SHA, date, mode, tool version).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 192 to 196
回到我们绘制白噪声的程序,导入语句之后的剩余三行是

```{code-cell} ipython
ϵ_values = np.random.randn(100)
ϵ_values = rng.standard_normal(100)
plt.plot(ϵ_values)
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

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

This section says “导入语句之后的剩余三行是…”, but the updated program now has an extra required line (rng = np.random.default_rng()) before rng.standard_normal(...). As written, the snippet will also fail if executed on its own because rng isn’t defined in this cell. Consider either (a) updating the text to reflect the correct number of lines and including the rng = ... line in this code cell, or (b) explicitly stating this cell assumes rng was created earlier.

Copilot uses AI. Check for mistakes.
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