bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / random / _generator / Generator / permutation
cython_function_or_method
numpy.random._generator:Generator.permutation
Signature
def permutation(x, axis = 0)Summary
Randomly permute a sequence, or return a permuted range.
Parameters
x: int or array_likeIf
xis an integer, randomly permutenp.arange(x). Ifxis an array, make a copy and shuffle the elements randomly.axis: int, optionalThe axis which
xis shuffled along. Default is 0.
Returns
out: ndarrayPermuted sequence or array range.
Examples
rng = np.random.default_rng()
✓rng.permutation(10)
✗array([5, 3, 8, 0, 1, 4, 2, 9, 6, 7])
rng.permutation([1, 4, 9, 12, 15])
✗array([ 4, 1, 12, 15, 9])
arr = np.arange(9).reshape((3, 3))
✓rng.permutation(arr)
✗array([[3, 4, 5],
[6, 7, 8],
[0, 1, 2]])
rng.permutation("abc")
✓Traceback (most recent call last):
File "<doctest numpy.random._generator:Generator.permutation[0]>", line 1, in <module>
rng.permutation("abc")
~~~~~~~~~~~~~~~^^^^^^^
File "numpy/random/_generator.pyx", line 4965, in numpy.random._generator.Generator.permutation
numpy.exceptions.AxisError: axis 0 is out of bounds for array of dimension 0
arr = np.arange(9).reshape((3, 3))
✓rng.permutation(arr, axis=1)
✗array([[2, 0, 1],
[5, 3, 4],
[8, 6, 7]])
Aliases
numpy.random.Generator.permutation