mindspore.ops.Randperm

class mindspore.ops.Randperm(max_length=1, pad=-1, dtype=mstype.int32)[source]

Generates n random samples from 0 to n-1 without repeating. If max_length > n, the last max_length-n elements will be filled with pad.

Parameters
  • max_length (int) – Number of items expected to get and the number must be greater than 0. Default: 1.

  • pad (int) – The pad value to be filled. Default: -1.

  • dtype (mindspore.dtype) – The type of output. Default: mindspore.int32.

Inputs:
  • n (Tensor[int32]) - The input tensor with shape: (1,) and the number must be in [0, max_length].

Outputs:
  • output (Tensor) - The output Tensor with shape: (max_length,) and type: dtype.

Raises
Supported Platforms:

Ascend GPU

Examples

>>> # The result of every execution is different because this operator will generate n random samples.
>>> randperm = ops.Randperm(max_length=30, pad=-1)
>>> n = Tensor([20], dtype=mindspore.int32)
>>> output = randperm(n)
>>> print(output)
[15 6 11 19 14 16 9 5 13 18 4 10 8 0 17 2 1 12 3 7
 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]