flopscope.numpy.random.Generator.shuffle
fnp.random.Generator.shuffle(self, x, axis=0)
Modify an array or sequence in-place by shuffling its contents.
Adapted from NumPy docs np.random.Generator.shuffle
Cost
Flopscope Context
In-place shuffle; cost = shape[axis] (Fisher-Yates draws).
The order of sub-arrays is changed but their contents remains the same.
Parameters
- x:ndarray or MutableSequence
The array, list or mutable sequence to be shuffled.
- axis:int, optional
The axis which
xis shuffled along. Default is 0. It is only supported onndarrayobjects.
Returns
- :None
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
>>> rng = flops.random.default_rng()
>>> arr = flops.arange(10)
>>> arr
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> rng.shuffle(arr)
>>> arr
array([2, 0, 7, 5, 1, 4, 8, 9, 3, 6]) # random>>> arr = flops.arange(9).reshape((3, 3))
>>> arr
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> rng.shuffle(arr)
>>> arr
array([[3, 4, 5], # random
[6, 7, 8],
[0, 1, 2]])>>> arr = flops.arange(9).reshape((3, 3))
>>> arr
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> rng.shuffle(arr, axis=1)
>>> arr
array([[2, 0, 1], # random
[5, 3, 4],
[8, 6, 7]])