randperm_cn.rst 1.2 KB
Newer Older
C
cc 已提交
1 2
.. _cn_api_tensor_random_randperm:

T
tianshuo78520a 已提交
3 4
randperm
-------------------------------
C
cc 已提交
5

6
.. py:function:: paddle.randperm(n, dtype="int64", name=None)
C
cc 已提交
7

S
swtkiwi 已提交
8
:alias_main: paddle.randperm
9
:alias: paddle.tensor.randperm, paddle.tensor.random.randperm
S
swtkiwi 已提交
10

11
该OP返回一个数值在0到n-1、随机排列的序列。
S
swtkiwi 已提交
12

13 14 15 16 17
参数:
::::::::::
  - **n** (int) - 随机序列的上限(不包括在序列中),应该大于0。 
  - **dtype** (str|np.dtype|core.VarDesc.VarType, 可选) - 输出Tensor的数据类型,支持int32、int64、float32、float64。默认值为"int64".
  - **name** (str, 可选) - 输出的名字。一般无需设置,默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。
S
swtkiwi 已提交
18

19 20 21
返回
::::::::::
  Variable:一个数值在0到n-1、随机排列的序列。数据类型为 ``dtype`` 。
C
cc 已提交
22

23 24 25 26
抛出异常
::::::::::
  - ValueError - 如果 ``n`` 不大于0.
  - TypeError - 如果 ``dtype`` 不是int32、int64、float32、float64.
C
cc 已提交
27

28 29
代码示例
::::::::::
C
cc 已提交
30 31 32 33

..  code-block:: python

    import paddle
34 35 36 37 38 39 40 41

    paddle.enable_imperative()

    result_1 = paddle.randperm(5)
    # [4 1 2 3 0]

    result_2 = paddle.randperm(7, 'int32')
    # [1 6 2 0 4 3 5]