[functions.md] Update np.random → Generator API#541
Open
Chihiro2000GitHub wants to merge 1 commit intomainfrom
Open
[functions.md] Update np.random → Generator API#541Chihiro2000GitHub wants to merge 1 commit intomainfrom
Chihiro2000GitHub wants to merge 1 commit intomainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR updates
lectures/functions.mdas 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 onpython_by_example.md: #538Point 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 isrng.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.