PyTorch torch.full 関数


Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

torch.fullPyTorch で指定された値を埋めたテンソルを作成するための関数です。

関数定義

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 リファレンスマニュアル

その他の拡張