Skip to content

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

Open
Chihiro2000GitHub wants to merge 1 commit intomainfrom
update-python-by-example-rng
Open

[python_by_example.md] Update np.random → Generator API#538
Chihiro2000GitHub wants to merge 1 commit intomainfrom
update-python-by-example-rng

Conversation

@Chihiro2000GitHub
Copy link
Copy Markdown
Collaborator

This PR updates legacy NumPy random API usage in python_by_example.md to the recommended Generator API.

I introduced a local rng = np.random.default_rng() and replaced the relevant legacy random calls using the new Generator API.

In the main lecture flow, I introduced rng only once and then reused it in subsequent cells, in order to keep the structure and presentation as close to the original as possible.

For the exercise solutions, I took a slightly different approach and introduced rng within each solution block. My reasoning was that these solutions seemed more natural as relatively self-contained answer units, especially since the exercise statements explicitly specify the relevant imports. That said, if this is not the preferred approach, it should be easy to revise by removing those local rng definitions.

I also updated the first sentence in Section 3.3.1.3 (“Subpackages”), since it explicitly referred to the legacy line np.random.randn(100) and would otherwise have become inconsistent with the revised code.

I built the lecture locally to check that the changes work as expected.

I’d be very glad to hear any thoughts, especially on the choice to define rng separately within each exercise solution block.

@github-actions
Copy link
Copy Markdown

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.

1 participant