PyTorch torch.numel 関数


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

torch.numelPyTorch でテンソル内の要素の総数を計算するための関数です。

関数定義

torch.numel(input)

使用例

実例

import torch

x = torch.randn(3, 4, 5)
print("要素総数:", torch.numel(x))

y = torch.tensor([1, 2, 3, 4, 5])
print("要素総数:", torch.numel(y))

出力結果は次のとおりです:

元素总数: 60
元素总数: 5

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

その他の拡張