Summary

  • Create an rng object with np.random.default_rng(), you can seed it for reproducible results.
  • You can draw samples from probability distributions, including from the binomial and normal distributions.
  • You can shuffle arrays in place with rng.shuffle().

Whether you’re simulating probability distributions or just want a random number, it’s easy to do with Python’s NumPy library.

Creating the random number generator

To be able to generate random numbers with NumPy, you need to create the random number generator. You can do this after importing the library with a simple command:

import numpy as nprng = np.random.default_rng()

Don’t forget…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help