Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.numel function

PyTorch torch.numel function


PyTorch torch reference manual 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

)

print

(

"Total number of elements:"

,

torch.

numel

(

x

)

)

y

=

torch.

tensor

(

[

1

,

2

,

3

,

4

,

5

]

)

print

(

"Total number of elements:"

,

torch.

numel

(

y

)

)

The output is:

元素总数: 60

元素总数: 5


PyTorch torch reference manual PyTorch torch reference manual