前言
记录randperm用法。
方法介绍
torch.randperm(n)
这个方法将[0, n)中的元素随机排列,函数名randperm
是random permutation
缩写。
permutation
的意思是排列。
代码示例
import torch
torch.randperm(10)
tensor([1, 5, 6, 8, 4, 0, 7, 2, 3, 9])
torch.randperm(10).tolist()
[4, 8, 6, 9, 3, 0, 5, 2, 1, 7]