[functions.md] Update np.random → Generator API#541
[functions.md] Update np.random → Generator API#541Chihiro2000GitHub wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Many thanks @Chihiro2000GitHub,
This looks great overall!
One small wording issue: after this change, technically speaking, rng.uniform is a Generator method rather than a standalone function, so the text saying "This object is a function" / "the function rng.uniform" is slightly inaccurate.
Could we reword that section to say that rng.uniform is a callable, i.e., an object that can be called using parentheses?
Then the final sentence could say "passing a function, method, or other callable object" rather than only "passing a function."
|
Thanks very much for the clear guidance, @HumphreyYang ! I would be grateful if you could take another look when you have time. |
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.