mindspore.mint.randperm
- mindspore.mint.randperm(n, *, generator=None, dtype=mstype.int64)[source]
Generates random permutation of integers from 0 to n-1.
- 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 or equal to zero. When n is 0, an empty Tensor is returned.
- Keyword Arguments:
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 negative.
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,)