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 / permuted

cython_function_or_method

numpy.random._generator:Generator.permuted

Signature

def   permuted ( x axis = None out = None )

Summary

Randomly permute x along axis axis.

Extended Summary

Unlike shuffle, each slice along the given axis is shuffled independently of the others.

Parameters

x : array_like, at least one-dimensional

Array to be shuffled.

axis : int, optional

Slices of x in this axis are shuffled. Each slice is shuffled independently of the others. If axis is None, the flattened array is shuffled.

out : ndarray, optional

If given, this is the destination of the shuffled array. If out is None, a shuffled copy of the array is returned.

Returns

: ndarray

If out is None, a shuffled copy of x is returned. Otherwise, the shuffled array is stored in out, and out is returned

Notes

An important distinction between methods shuffle and permuted is how they both treat the axis parameter which can be found at generator-handling-axis-parameter.

Examples

Create a `numpy.random.Generator` instance:
rng = np.random.default_rng()
Create a test array:
x = np.arange(24).reshape(3, 8)
x
Shuffle the rows of `x`:
y = rng.permuted(x, axis=1)
y
`x` has not been modified:
x
To shuffle the rows of `x` in-place, pass `x` as the `out` parameter:
y = rng.permuted(x, axis=1, out=x)
x
Note that when the ``out`` parameter is given, the return value is ``out``:
y is x

See also

permutation
shuffle

Aliases

  • numpy.random.Generator.permuted