You are viewing an older version (2.4.3).Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / 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_like

If x is an integer, randomly permute np.arange(x). If x is an array, make a copy and shuffle the elements randomly.

axis : int, optional

The axis which x is shuffled along. Default is 0.

Returns

out : ndarray

Permuted sequence or array range.

Examples

rng = np.random.default_rng()
✓
rng.permutation(10)
✗
array([9, 8, 4, 6, 7, 5, 3, 0, 2, 1])
rng.permutation([1, 4, 9, 12, 15])
✗
array([15,  9,  1, 12,  4])
arr = np.arange(9).reshape((3, 3))
✓
rng.permutation(arr)
✗
array([[3, 4, 5],
       [0, 1, 2],
       [6, 7, 8]])
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, 1, 0],
       [5, 4, 3],
       [8, 7, 6]])

Aliases

  • numpy.random.Generator.permutation

Referenced by