评价此页

torch.numel#

torch.numel(input: Tensor) int#

返回 input 张量中的元素总数。

参数

input (Tensor) – 输入张量。

示例

>>> a = torch.randn(1, 2, 3, 4, 5)
>>> torch.numel(a)
120
>>> a = torch.zeros(4,4)
>>> torch.numel(a)
16