pytorch获取张量元素个数numel()的用法

numel就是"number of elements"的简写。numel()能够直接返回int类型的元素个数python

import torch

a = torch.randn(1, 2, 3, 4)
b = a.numel()
print(type(b)) # int
print(b) # 24

经过numel()函数,咱们能够迅速查看一个张量到底又多少元素。函数

相关文章
相关标签/搜索