mindspore.ops.shuffle

View Source On Gitee
mindspore.ops.shuffle(x, seed=None)[source]

Randomly shuffles a Tensor along its first dimension.

Parameters
  • x (Tensor) – The Tensor need be shuffled.

  • seed (int, optional) – Random seed used for random number generation, must be non-negative. If seed is 0, which will be replaced with a randomly generated value. Default: None , which will be treated as 0.

Returns

Tensor. The shape and type are the same as the input x.

Raises

TypeError – If data type of seed is not None or non-negative int.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> from mindspore import dtype as mstype
>>> x = Tensor(np.array([1, 2, 3, 4]), mstype.float32)
>>> output = ops.shuffle(x, seed=1)
>>> print(output)
[3. 4. 2. 1.]