{ } Raw JSON

bundles / numpy 2.4.4 / numpy / random / RandomState / permutation

cython_function_or_method

numpy.random:RandomState.permutation

Signature

def permutation(x)

Summary

Randomly permute a sequence, or return a permuted range.

Extended Summary

If x is a multi-dimensional array, it is only shuffled along its first index.

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.

Returns

out : ndarray

Permuted sequence or array range.

Examples

np.random.permutation(10)
✗
array([8, 5, 2, 7, 0, 3, 6, 4, 1, 9])
np.random.permutation([1, 4, 9, 12, 15])
✗
array([ 1,  9, 12,  4, 15])
arr = np.arange(9).reshape((3, 3))
✓
np.random.permutation(arr)
✗
array([[6, 7, 8],
       [0, 1, 2],
       [3, 4, 5]])

See also

random.Generator.permutation

which should be used for new code.

Aliases

  • numpy.random.permutation
  • numpy.random.RandomState.permutation