summaryrefslogtreecommitdiff
path: root/doc/source/reference/random
diff options
context:
space:
mode:
Diffstat (limited to 'doc/source/reference/random')
-rw-r--r--doc/source/reference/random/generator.rst14
-rw-r--r--doc/source/reference/random/index.rst24
-rw-r--r--doc/source/reference/random/new-or-different.rst22
3 files changed, 30 insertions, 30 deletions
diff --git a/doc/source/reference/random/generator.rst b/doc/source/reference/random/generator.rst
index a359d2253..7934be98a 100644
--- a/doc/source/reference/random/generator.rst
+++ b/doc/source/reference/random/generator.rst
@@ -71,13 +71,13 @@ By default, `Generator.permuted` returns a copy. To operate in-place with
`Generator.permuted`, pass the same array as the first argument *and* as
the value of the ``out`` parameter. For example,
- >>> rg = np.random.default_rng()
+ >>> rng = np.random.default_rng()
>>> x = np.arange(0, 15).reshape(3, 5)
>>> x
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
- >>> y = rg.permuted(x, axis=1, out=x)
+ >>> y = rng.permuted(x, axis=1, out=x)
>>> x
array([[ 1, 0, 2, 4, 3], # random
[ 6, 7, 8, 9, 5],
@@ -97,13 +97,13 @@ which dimension of the input array to use as the sequence. In the case of a
two-dimensional array, ``axis=0`` will, in effect, rearrange the rows of the
array, and ``axis=1`` will rearrange the columns. For example
- >>> rg = np.random.default_rng()
+ >>> rng = np.random.default_rng()
>>> x = np.arange(0, 15).reshape(3, 5)
>>> x
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
- >>> rg.permutation(x, axis=1)
+ >>> rng.permutation(x, axis=1)
array([[ 1, 3, 2, 0, 4], # random
[ 6, 8, 7, 5, 9],
[11, 13, 12, 10, 14]])
@@ -116,7 +116,7 @@ how `numpy.sort` treats it. Each slice along the given axis is shuffled
independently of the others. Compare the following example of the use of
`Generator.permuted` to the above example of `Generator.permutation`:
- >>> rg.permuted(x, axis=1)
+ >>> rng.permuted(x, axis=1)
array([[ 1, 0, 2, 4, 3], # random
[ 5, 7, 6, 9, 8],
[10, 14, 12, 13, 11]])
@@ -131,9 +131,9 @@ Shuffling non-NumPy sequences
a sequence that is not a NumPy array, it shuffles that sequence in-place.
For example,
- >>> rg = np.random.default_rng()
+ >>> rng = np.random.default_rng()
>>> a = ['A', 'B', 'C', 'D', 'E']
- >>> rg.shuffle(a) # shuffle the list in-place
+ >>> rng.shuffle(a) # shuffle the list in-place
>>> a
['B', 'D', 'A', 'E', 'C'] # random
diff --git a/doc/source/reference/random/index.rst b/doc/source/reference/random/index.rst
index 13ce7c40c..69d597874 100644
--- a/doc/source/reference/random/index.rst
+++ b/doc/source/reference/random/index.rst
@@ -84,10 +84,10 @@ different
.. code-block:: python
try:
- rg_integers = rg.integers
+ rng_integers = rng.integers
except AttributeError:
- rg_integers = rg.randint
- a = rg_integers(1000)
+ rng_integers = rng.randint
+ a = rng_integers(1000)
Seeds can be passed to any of the BitGenerators. The provided value is mixed
via `SeedSequence` to spread a possible sequence of seeds across a wider
@@ -97,8 +97,8 @@ is wrapped with a `Generator`.
.. code-block:: python
from numpy.random import Generator, PCG64
- rg = Generator(PCG64(12345))
- rg.standard_normal()
+ rng = Generator(PCG64(12345))
+ rng.standard_normal()
Here we use `default_rng` to create an instance of `Generator` to generate a
random float:
@@ -146,10 +146,10 @@ As a convenience NumPy provides the `default_rng` function to hide these
details:
>>> from numpy.random import default_rng
->>> rg = default_rng(12345)
->>> print(rg)
+>>> rng = default_rng(12345)
+>>> print(rng)
Generator(PCG64)
->>> print(rg.random())
+>>> print(rng.random())
0.22733602246716966
One can also instantiate `Generator` directly with a `BitGenerator` instance.
@@ -158,16 +158,16 @@ To use the default `PCG64` bit generator, one can instantiate it directly and
pass it to `Generator`:
>>> from numpy.random import Generator, PCG64
->>> rg = Generator(PCG64(12345))
->>> print(rg)
+>>> rng = Generator(PCG64(12345))
+>>> print(rng)
Generator(PCG64)
Similarly to use the older `MT19937` bit generator (not recommended), one can
instantiate it directly and pass it to `Generator`:
>>> from numpy.random import Generator, MT19937
->>> rg = Generator(MT19937(12345))
->>> print(rg)
+>>> rng = Generator(MT19937(12345))
+>>> print(rng)
Generator(MT19937)
What's New or Different
diff --git a/doc/source/reference/random/new-or-different.rst b/doc/source/reference/random/new-or-different.rst
index 6cab0f729..a81543926 100644
--- a/doc/source/reference/random/new-or-different.rst
+++ b/doc/source/reference/random/new-or-different.rst
@@ -58,18 +58,18 @@ And in more detail:
from numpy.random import Generator, PCG64
import numpy.random
- rg = Generator(PCG64())
- %timeit -n 1 rg.standard_normal(100000)
+ rng = Generator(PCG64())
+ %timeit -n 1 rng.standard_normal(100000)
%timeit -n 1 numpy.random.standard_normal(100000)
.. ipython:: python
- %timeit -n 1 rg.standard_exponential(100000)
+ %timeit -n 1 rng.standard_exponential(100000)
%timeit -n 1 numpy.random.standard_exponential(100000)
.. ipython:: python
- %timeit -n 1 rg.standard_gamma(3.0, 100000)
+ %timeit -n 1 rng.standard_gamma(3.0, 100000)
%timeit -n 1 numpy.random.standard_gamma(3.0, 100000)
@@ -94,9 +94,9 @@ And in more detail:
.. ipython:: python
- rg = Generator(PCG64(0))
- rg.random(3, dtype='d')
- rg.random(3, dtype='f')
+ rng = Generator(PCG64(0))
+ rng.random(3, dtype='d')
+ rng.random(3, dtype='f')
* Optional ``out`` argument that allows existing arrays to be filled for
select distributions
@@ -112,7 +112,7 @@ And in more detail:
.. ipython:: python
existing = np.zeros(4)
- rg.random(out=existing[:2])
+ rng.random(out=existing[:2])
print(existing)
* Optional ``axis`` argument for methods like `~.Generator.choice`,
@@ -121,9 +121,9 @@ And in more detail:
.. ipython:: python
- rg = Generator(PCG64(123456789))
+ rng = Generator(PCG64(123456789))
a = np.arange(12).reshape((3, 4))
a
- rg.choice(a, axis=1, size=5)
- rg.shuffle(a, axis=1) # Shuffle in-place
+ rng.choice(a, axis=1, size=5)
+ rng.shuffle(a, axis=1) # Shuffle in-place
a