randperm

paddle. randperm ( n, dtype='int64', name=None ) [源代码]

返回一个数值在 0 到 n-1、随机排列的 1-D Tensor,数据类型为 dtype

参数

  • n (int) - 随机序列的上限(不包括在序列中),应该大于 0。

  • dtype (str|np.dtype,可选) - 输出 Tensor 的数据类型,支持 int32、int64、float32、float64。默认值为 int64。

  • name (str,可选) - 具体用法请参见 Name,一般无需设置,默认值为 None。

返回

Tensor:一个数值在 0 到 n-1、随机排列的 1-D Tensor,数据类型为 dtype

代码示例

>>> 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])

使用本API的教程文档