randperm

paddle. randperm ( n, dtype='int64', name=None ) [source]

Returns a 1-D Tensor filled with random permutation values from 0 to n-1, with dtype.

Parameters
  • n (int) – The upper bound (exclusive), and it should be greater than 0.

  • dtype (str|np.dtype, optional) – The data type of the output Tensor. Supported data types: int32, int64, float32, float64. Default is int64.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

A 1-D Tensor filled with random permutation values from 0 to n-1, with dtype.

Return type

Tensor

Examples

>>> import paddle

>>> out1 = paddle.randperm(5)
>>> print(out1)
>>> 
Tensor(shape=[5], dtype=int64, place=Place(cpu), stop_gradient=True,
[3, 0, 1, 4, 2])
>>> 

>>> out2 = paddle.randperm(7, 'int32')
>>> print(out2)
>>> 
Tensor(shape=[7], dtype=int32, place=Place(cpu), stop_gradient=True,
[3, 2, 0, 6, 5, 4, 1])
>>>