PyTorch torch.randint 関数


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

torch.randintPyTorch で整数のランダムテンソルを作成するための関数です。

関数定義

torch.randint(low, high, size, dtype, device, requires_grad)

使用例

実例

import torch

# 0から9のランダム整数テンソルを作成
x = torch.randint(0, 10, (3, 4))

print(x)

出力結果は:

tensor([[4, 5, 2, 6],
        [7, 9, 3, 1],
        [2, 8, 5, 4]])

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

その他の拡張