flopscope.numpy.random.Generator.permuted
fnp.random.Generator.permuted(self, x, *, axis=None, out=None)
Randomly permute `x` along axis `axis`.
Adapted from NumPy docs np.random.Generator.permuted
Permute along axis; cost from input array size.
Randomly permute x along axis axis.
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
xin this axis are shuffled. Each slice is shuffled independently of the others. Ifaxisis None, the flattened array is shuffled.- out:ndarray, optional
If given, this is the destination of the shuffled array. If
outis None, a shuffled copy of the array is returned.
Returns
- :ndarray
If
outis None, a shuffled copy ofxis returned. Otherwise, the shuffled array is stored inout, andoutis returned
See also
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 flops.random.Generator instance:
>>> rng = flops.random.default_rng()Create a test array:
>>> x = flops.arange(24).reshape(3, 8)
>>> x
array([[ 0, 1, 2, 3, 4, 5, 6, 7],
[ 8, 9, 10, 11, 12, 13, 14, 15],
[16, 17, 18, 19, 20, 21, 22, 23]])Shuffle the rows of x:
>>> y = rng.permuted(x, axis=1)
>>> y
array([[ 4, 3, 6, 7, 1, 2, 5, 0], # random
[15, 10, 14, 9, 12, 11, 8, 13],
[17, 16, 20, 21, 18, 22, 23, 19]])x has not been modified:
>>> x
array([[ 0, 1, 2, 3, 4, 5, 6, 7],
[ 8, 9, 10, 11, 12, 13, 14, 15],
[16, 17, 18, 19, 20, 21, 22, 23]])To shuffle the rows of x in-place, pass x as the out
parameter:
>>> y = rng.permuted(x, axis=1, out=x)
>>> x
array([[ 3, 0, 4, 7, 1, 6, 2, 5], # random
[ 8, 14, 13, 9, 12, 11, 15, 10],
[17, 18, 16, 22, 19, 23, 20, 21]])Note that when the out parameter is given, the return
value is out:
>>> y is x
True