Skip to content

[functions.md] Update np.random → Generator API#541

Open
Chihiro2000GitHub wants to merge 1 commit intomainfrom
update-functions-rng
Open

[functions.md] Update np.random → Generator API#541
Chihiro2000GitHub wants to merge 1 commit intomainfrom
update-functions-rng

Conversation

@Chihiro2000GitHub
Copy link
Copy Markdown
Collaborator

@Chihiro2000GitHub Chihiro2000GitHub commented Apr 26, 2026

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

Approach

A single rng = np.random.default_rng() is introduced where random draws first appear in the main lecture flow (the "4.4.1. Random Draws" section) and reused across subsequent code cells, following the natural notebook execution order. This avoids redundant redefinition while keeping the changes minimal.

For exercise solution blocks, which are intended to be self-contained, rng = np.random.default_rng() is defined locally at the top of each relevant solution cell. This aligns with the strategy I took in the previous pull request on python_by_example.md: #538

Point for review

In Section 4.4.2. ("Adding Conditions"), the lecture demonstrates passing a callable as an argument to generate_data(). After this migration, the object passed is rng.uniform, which is technically a method rather than a function. As a result, a few sentences related to this - such as "by just passing the desired generator type as a function," "This object is a function", and "bound to the function rng.uniform" - are no longer strictly accurate.

I chose to leave these sentences unchanged for now, as this is an introductory programming lecture and I was uncertain whether introducing terms like "method," "callable," or "function-like object" would help or confuse readers who are likely encountering these concepts for the first time.

I would appreciate the reviewer's guidance on how to handle this wording. I am happy to revise the sentences based on your feedback and will request a re-review after making any requested changes. I will only merge once you are satisfied with the result.

@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