PyTorch torch.numel function
PyTorch torch reference manual
torch.numel is a function in PyTorch that computes the total number of elements in a tensor.
Function definition
torch.numel(input)
Usage examples
Example
import
torch
x
=
torch.
randn
(
3
,
4
,
5
)
(
"Total number of elements:"
,
torch.
numel
(
x
)
)
y
=
torch.
tensor
(
[
1
,
2
,
3
,
4
,
5
]
)
(
"Total number of elements:"
,
torch.
numel
(
y
)
)
The output is:
元素总数: 60
元素总数: 5