megengine.random.shuffle¶
- shuffle(inp)¶
Modify a sequence in-place by shuffling its contents. This function only shuffles the Tensor along the first axis of a multi-dimensional Tensor. The order of sub-Tensors is changed but their contents remains the same.
- Parameters
inp (
Tensor
) – input tensor.- Returns
None.
Examples
>>> import numpy as np >>> import megengine.random as rand >>> x = mge.tensor(np.arange(10)) >>> rand.shuffle(x) >>> x.numpy() array([4, 5, 9, 6, 2, 8, 1, 0, 3, 7], dtype=int32) >>> y = mge.tensor(np.arange(18)).reshape(6,3) >>> rand.shuffle(y) >>> y.numpy() array([[ 3, 4, 5], [ 6, 7, 8], [15, 16, 17], [ 0, 1, 2], [12, 13, 14], [ 9, 10, 11]], dtype=int32)