pytorch numel()统计tensor中包含的元素个数

参考:https://blog.csdn.net/schmiloo/article/details/107020922

统计tensor张量包含的元素个数

import torch
x = torch.randn(3,3)
print("number elements of x is ",x.numel())
y = torch.randn(3,10,5)
print("number elements of y is ",y.numel())

输出内容:

number elements of x is  9
number elements of y is  150

你可能感兴趣的:(pytorch入坑指南,pytorch,numel)