summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/source/reference/random/generator.rst2
-rw-r--r--numpy/random/_generator.pyx16
2 files changed, 18 insertions, 0 deletions
diff --git a/doc/source/reference/random/generator.rst b/doc/source/reference/random/generator.rst
index a0ef01dcb..c73ac7b7b 100644
--- a/doc/source/reference/random/generator.rst
+++ b/doc/source/reference/random/generator.rst
@@ -88,6 +88,8 @@ Note that when ``out`` is given, the return value is ``out``:
>>> y is x
True
+.. _generator-handling-the-axis-parameter:
+
Handling the ``axis`` parameter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An important distinction for these methods is how they handle the ``axis``
diff --git a/numpy/random/_generator.pyx b/numpy/random/_generator.pyx
index 3eb5876ec..81435731e 100644
--- a/numpy/random/_generator.pyx
+++ b/numpy/random/_generator.pyx
@@ -4571,12 +4571,24 @@ cdef class Generator:
-------
None
+ .. note::
+ An important distinction between methods ``shuffle`` and ``permuted`` is
+ how they both treat the ``axis`` parameter which can be found at
+ :ref:`generator-handling-the-axis-parameter`.
+
+ See Also
+ --------
+ permuted
+ permutation
+
Examples
--------
>>> rng = np.random.default_rng()
>>> arr = np.arange(10)
>>> rng.shuffle(arr)
>>> arr
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+ >>> arr
[1 7 5 2 9 4 3 6 0 8] # random
>>> arr = np.arange(9).reshape((3, 3))
@@ -4587,6 +4599,10 @@ cdef class Generator:
[0, 1, 2]])
>>> arr = np.arange(9).reshape((3, 3))
+ >>> arr
+ array([[0, 1, 2],
+ [3, 4, 5],
+ [6, 7, 8]])
>>> rng.shuffle(arr, axis=1)
>>> arr
array([[2, 0, 1], # random