Skip to content

[scipy.md] Update np.random → Generator API#547

Merged
mmcky merged 2 commits intomainfrom
update-scipy-rng
May 8, 2026
Merged

[scipy.md] Update np.random → Generator API#547
mmcky merged 2 commits intomainfrom
update-scipy-rng

Conversation

@Chihiro2000GitHub
Copy link
Copy Markdown
Collaborator

Summary

This PR updates lectures/scipy.md as part of the NumPy random API migration described in QuantEcon/meta#299.

The changes are limited to the following:

  • Replace np.random.beta(...) with rng = np.random.default_rng() / rng.beta(...)
  • Update the surrounding wording: "functions" → "tools" to avoid implying module-level functions
  • Replace np.random.randn(...) with rng.standard_normal(...) in "12.3.3. Other Goodies in scipy.stats"
  • Replace np.random.randn(...) with rng.standard_normal(...) in the Monte Carlo exercise solution (Exercise 12.3)

Each code block defines its own rng locally. The exercise solution block remains self-contained.
No fixed seed is introduced, as the original lecture did not use one.
No Numba-related code was present in this file.

Hi @mmcky and @HumphreyYang, I'd be grateful if you could take a look when you have time.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

@github-actions github-actions Bot temporarily deployed to pull request May 6, 2026 02:31 Inactive
@jstac
Copy link
Copy Markdown
Contributor

jstac commented May 7, 2026

Many thanks @Chihiro2000GitHub , this looks good to me.

Copy link
Copy Markdown
Member

@HumphreyYang HumphreyYang left a comment

Choose a reason for hiding this comment

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

Many thanks @jstac and @Chihiro2000GitHub, just one very minor suggestion!

Comment thread lectures/scipy.md Outdated

x = np.random.randn(200)
y = 2 * x + 0.1 * np.random.randn(200)
rng = np.random.default_rng()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I remember the convention was to use a single rng for the main text and separate ones in solution blocks (see this PR discussion). According to that, I think we can reuse the rng on line 110 here.

@Chihiro2000GitHub
Copy link
Copy Markdown
Collaborator Author

Thanks for pointing this out, @HumphreyYang! I had missed that convention.

I’ve removed the additional rng definition on line 192 so that the main text reuses the existing rng from line 110.

@mmcky
Copy link
Copy Markdown
Contributor

mmcky commented May 8, 2026

Thanks @Chihiro2000GitHub, @HumphreyYang and @jstac

@mmcky mmcky merged commit fb75a07 into main May 8, 2026
5 checks passed
@mmcky mmcky deleted the update-scipy-rng branch May 8, 2026 09:33
@mmcky
Copy link
Copy Markdown
Contributor

mmcky commented May 8, 2026

✅ Translation sync completed (zh-cn)

Target repo: QuantEcon/lecture-python-programming.zh-cn
Translation PR: QuantEcon/lecture-python-programming.zh-cn#63
Files synced (1):

  • lectures/scipy.md

@mmcky
Copy link
Copy Markdown
Contributor

mmcky commented May 8, 2026

✅ Translation sync completed (fa)

Target repo: QuantEcon/lecture-python-programming.fa
Translation PR: QuantEcon/lecture-python-programming.fa#120
Files synced (1):

  • lectures/scipy.md

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants