pytorch.tensor常见操作
文章目录
1. torch.randperm2. torch.repeat_interleave3. torch.linspace4. torch.bmm
1. torch.randperm
作用:返回从0到n - 1的整数的随机排列。特别适合生成相关数据
torch.randperm(n, *, generator=None, out=None, dtype=torch.int64, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) → Tensor
代码
import torch
num_rows, num_cols = 3,4
x = torch.randperm(num_rows*num_cols).reshape(num_rows,num_cols)
print(f"x={x}")
共有 0 条评论