现在位置: 首页 > PyTorch 教程 > 正文

PyTorch torch.full 函数


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

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)

输出结果为:

tensor([[7., 7., 7., 7.],
        [7., 7., 7., 7.],
        [7., 7., 7., 7.]])

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