TUTORIALAI & dataFETCHED

PyTorch torch.randperm 函数

PyTorch torch.randperm 函数 Pytorch torch 参考手册 torch.randperm 是 PyTorch 中用于创建 0 到 n-1 随机排列的函数。 函数定义 torch.randperm(n, dtype, device, requires_grad) 使用示例 实例 [mycode4 type='python'] import torch # 创建 0 到..

Updated 7/16/2026

Tutorial detail pages default to noindex.

PyTorch torch.randperm 函数


Pytorch torch 参考手册 Pytorch torch 参考手册

torch.randperm 是 PyTorch 中用于创建 0 到 n-1 随机排列的函数。

函数定义

torch.randperm(n, dtype, device, requires_grad)

使用示例

实例

import torch

# 创建 0 到 9 的随机排列
x = torch.randperm(10)

print(x)

Pytorch torch 参考手册 Pytorch torch 参考手册