Skip to content

Commit 6456001

Browse files
authored
Merge pull request #185 from rsokl/numpy-random
numpy.random: fix broken link and update syntax to use new RNG system
2 parents ecfd320 + 4ff6749 commit 6456001

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Python/Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,22 @@ Numpy has other functions for creating sequential arrays, such as producing an a
150150
## Creating Arrays Using Random Sampling
151151
Several functions can be accessed from `np.random`, which populate arrays of a user-specified shape by drawing randomly from a specified statistical distribution:
152152
```python
153+
# construct a new random number generator
154+
>>> rng = np.random.default_rng()
155+
153156
# create a shape-(3,3) array by drawing its entries randomly
154157
# from the uniform distribution [0, 1)
155-
>>> np.random.rand(3,3)
158+
>>> rng.random((3, 3))
156159
array([[ 0.09542611, 0.13183498, 0.39836068],
157160
[ 0.7358235 , 0.77640024, 0.74913595],
158161
[ 0.37702688, 0.86617624, 0.39846429]])
159162

160163
# create a shape-(5,) array by drawing its entries randomly
161164
# from a mean-0, variance-1 normal (a.k.a. Gaussian) distribution
162-
>>> np.random.randn(5)
165+
>>> rng.normal(size=(5,))
163166
array([-1.11262121, -0.35392007, 0.4245215 , -0.81995588, 0.65412323])
164167
```
165-
There are [many more functions](https://numpy.org/doc/stable/reference/routines.random.html#distributions) to read about that allow you to draw from a wide variety of statistical distributions. This only scratches the surface of random number generation in NumPy.
168+
There are [many more functions](https://numpy.org/doc/stable/reference/random/generator.html#simple-random-data) to read about that allow you to draw from a wide variety of statistical distributions. This only scratches the surface of random number generation in NumPy.
166169

167170
<!-- #endregion -->
168171

0 commit comments

Comments
 (0)