bundles / numpy 2.5.0.dev0+git20251130.2de293a / 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_likeIf
xis an integer, randomly permutenp.arange(x). Ifxis an array, make a copy and shuffle the elements randomly.
Returns
out: ndarrayPermuted 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.permutationnumpy.random.RandomState.permutation