[numpy.md] Update np.random → Generator API#549
Open
Chihiro2000GitHub wants to merge 1 commit intomainfrom
Open
[numpy.md] Update np.random → Generator API#549Chihiro2000GitHub wants to merge 1 commit intomainfrom
Chihiro2000GitHub wants to merge 1 commit intomainfrom
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
This PR migrates legacy NumPy random API calls in
numpy.mdas part of QuantEcon/meta#299.All
np.random.randn,np.random.binomial, andfrom numpy.random import uniformusages are replaced with the Generator API vianp.random.default_rng().Details
rng = np.random.default_rng()is introduced at the first point of use (Mutability section) and reused throughout the main lecture text.np_ex3,np_ex4) define their own localrngto remain self-contained.np_ex4(Part 1 and Part 2, exercise and solution) retains seed 123 vianp.random.default_rng(123), matching the original intent of reproducible comparison between broadcasting and for-loop results.DiscreteRVin thenp_ex2solution storesself.rng = np.random.default_rng()in__init__and usesself.rng.uniform(...)indraw.jb build lectures);numpy.mdexecuted without errors in 30 seconds.Notes for reviewers
One item was intentionally left unchanged and would benefit from reviewer judgment:
The prose in the Sub-packages section currently reads:
After this migration, the code directly below uses
rng.standard_normal()andrng.binomial()rather thannp.random.xxx()directly. Technicallyrngis still obtained fromnp.random.default_rng(), so the sentence is not wrong — but it may feel slightly mismatched to a reader. Happy to update the wording if you think that would be clearer.Hi @mmcky and @HumphreyYang, I'd be grateful if you could take a look when you have time.