[uncertainty_traps.md] Update np.random → Generator API - #1011
Merged
Conversation
56 tasks
📖 Netlify Preview Ready!Preview URL: https://pr-1011--sunny-cactus-210e3e.netlify.app Commit: 📚 Changed LecturesBuild Info
|
kp992
approved these changes
Jul 31, 2026
Contributor
✅ Translation sync completed (zh-cn)Target repo: QuantEcon/lecture-python.zh-cn
|
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 usage in
uncertainty_traps.mdas part of QuantEcon/meta#299.The three
np.random.randn(...)calls are replaced with draws from an explicit generatorrng = np.random.default_rng(), which is created in the solution block and passed intogen_aggregates.Related PRs and issues
I checked for open PRs and issues related to this lecture. No open PR modifies
uncertainty_traps.md, and no open issue concerns this migration.Details
UncertaintyTrapEcon.gen_aggregatesnow takesrngas an argument, and its two draws userng.standard_normal(...).rng = np.random.default_rng()is created before the simulation loop,np.random.randn(sim_length)→rng.standard_normal(sim_length), and the twoecon.gen_aggregates()call sites passrng.@jit,@njit,@jitclass,parallel=True,prange) code.uncertainty_traps.mdexecuted without errors.Note for reviewers
gen_aggregatesnow takesrngas an argument, so its two call sites changed as well. Happy to give the class its own generator instead if you would rather keep the signature unchanged.Hi @mmcky and @HumphreyYang, I'd be grateful if you could take a look when you have time.