You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Python/Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.md
+6-3
Original file line number
Diff line number
Diff line change
@@ -150,19 +150,22 @@ Numpy has other functions for creating sequential arrays, such as producing an a
150
150
## Creating Arrays Using Random Sampling
151
151
Several functions can be accessed from `np.random`, which populate arrays of a user-specified shape by drawing randomly from a specified statistical distribution:
152
152
```python
153
+
# construct a new random number generator
154
+
>>> rng = np.random.default_rng()
155
+
153
156
# create a shape-(3,3) array by drawing its entries randomly
154
157
# from the uniform distribution [0, 1)
155
-
>>>np.random.rand(3,3)
158
+
>>>rng.random((3, 3))
156
159
array([[ 0.09542611, 0.13183498, 0.39836068],
157
160
[ 0.7358235 , 0.77640024, 0.74913595],
158
161
[ 0.37702688, 0.86617624, 0.39846429]])
159
162
160
163
# create a shape-(5,) array by drawing its entries randomly
161
164
# from a mean-0, variance-1 normal (a.k.a. Gaussian) distribution
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.
0 commit comments