PyTorch torch.full 函数
torch.full 是 PyTorch 中用于创建填充指定值的张量的函数。
函数定义
torch.full(size, fill_value, dtype=None, device=None, requires_grad=False)
使用示例
实例
import torch
# 创建 3x4 的张量,填充值为 7
x = torch.full((3, 4), 7)
print(x)
# 创建 3x4 的张量,填充值为 7
x = torch.full((3, 4), 7)
print(x)
输出结果为:
tensor([[7., 7., 7., 7.],
[7., 7., 7., 7.],
[7., 7., 7., 7.]])

Pytorch torch 参考手册