permutation#
- class braincore.random.permutation(x, axis=0, independent=False, key=None)[source]#
Randomly permute a sequence, or return a permuted range.
If x is a multi-dimensional array, it is only shuffled along its first index.
- Parameters:
x (int or array_like) – If x is an integer, randomly permute
np.arange(x). If x is an array, make a copy and shuffle the elements randomly.axis (int, optional) – The axis which x is shuffled along. Default is 0.
independent (bool, optional) – Whether to use independent random permutations for each batch. If
False(default), the same random permutation is used for all batches. IfTrue, each batch is shuffled independently. Ignored if x is an integer.key (PRNGKey, optional) – The key for the random number generator. If not given, the default random number generator is used.
- Returns:
out – Permuted sequence or array range.
- Return type:
ndarray
Examples
>>> import braincore as bc >>> bc.random.permutation(10) array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6]) # random
>>> bc.random.permutation([1, 4, 9, 12, 15]) array([15, 1, 9, 4, 12]) # random
>>> arr = np.arange(9).reshape((3, 3)) >>> bc.random.permutation(arr) array([[6, 7, 8], # random [0, 1, 2], [3, 4, 5]])