flopscope.numpy.random.Generator.permutation
fnp.random.Generator.permutation(self, x, axis=0)
Randomly permute a sequence, or return a permuted range.
Adapted from NumPy docs np.random.Generator.permutation
Cost
Flopscope Context
Random permutation; cost = shape[axis] (Fisher-Yates draws).
Parameters
- x:int or array_like
If
xis an integer, randomly permute flops.arange(x). Ifxis an array, make a copy and shuffle the elements randomly.- axis:int, optional
The axis which
xis shuffled along. Default is 0.
Returns
- out:ndarray
Permuted sequence or array range.
Examples
>>> rng = flops.random.default_rng()
>>> rng.permutation(10)
array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6]) # random>>> rng.permutation([1, 4, 9, 12, 15])
array([15, 1, 9, 4, 12]) # random>>> arr = flops.arange(9).reshape((3, 3))
>>> rng.permutation(arr)
array([[6, 7, 8], # random
[0, 1, 2],
[3, 4, 5]])>>> rng.permutation("abc")
Traceback (most recent call last):
...
flops.exceptions.AxisError: axis 0 is out of bounds for array of dimension 0>>> arr = flops.arange(9).reshape((3, 3))
>>> rng.permutation(arr, axis=1)
array([[0, 2, 1], # random
[3, 5, 4],
[6, 8, 7]])