mindspore.mint.randperm

View Source On Gitee
mindspore.mint.randperm(n, *, generator=None, dtype=mstype.int64)[source]

Generates random permutation of integers from 0 to n-1.

Warning

  • This is an experimental API that is subject to change or deletion.

Parameters
  • n (Union[Tensor, int]) – size of the permutation. int or Tensor with shape: () or (1,) and data type int64. The value of n must be greater than zero.

  • generator (mindspore.Generator, optional) – a pseudorandom number generator. Default: None, uses the default pseudorandom number generator.

  • dtype (mindspore.dtype, optional) – The type of output. Default: mstype.int64.

Returns

Tensor with shape (n,) and type dtype.

Raises
  • TypeError – If dtype is not supported.

  • ValueError – If n is a negative or 0 element.

  • ValueError – If n is larger than the maximal data of the set dtype.

Supported Platforms:

Ascend

Examples

>>> from mindspore import mint
>>> from mindspore import dtype as mstype
>>> n = 4
>>> output = mint.randperm(n, dtype=mstype.int64)
>>> print(output.shape)
(4,)