mindspore.ops.randperm
- mindspore.ops.randperm(n, seed=0, offset=0, dtype=mstype.int64)[source]
Generates random permutation of integers from 0 to n-1.
Returns the tensor with the determined shape inferred by n, the random numbers in it drawn from the data range that a given type can represent.
Warning
This is an experimental API that is subject to change or deletion.
- Parameters
n (Union[Tensor, int]) – The input n Tensor with shape: () or (1,) and with data type of int64. The value of n must be greater than zero.
seed (int, optional) – Random seed. Default:
0
. When seed is -1(only negative value), offset is 0, it's determined by time.offset (int, optional) – Offset to generate random numbers. Priority is higher than random seed. Default:
0
. It must be non-negative.dtype (mindspore.dtype, optional) – The type of output. Its value must be one of the following types: int32, int16, int8, uint8, int64, float64, float32, float16. Default: mstype.int64.
- Returns
Tensor. Its shape is specified by the required args n. Its type is specified by dtype. Otherwise is default.
- Raises
TypeError – If dtype is not allowed.
ValueError – If n is a negative or 0 element.
ValueError – If seed is a negative element.
ValueError – If n is larger than the maximal data of the set dtype.
- Supported Platforms:
CPU
Examples
>>> from mindspore import ops >>> from mindspore import dtype as mstype >>> n = 4 >>> seed = 0 >>> offset = 0 >>> output = ops.randperm(n, seed, offset, dtype=mstype.int64) >>> print(output) [0 2 1 3]