numel pytorch code example
Example: what is numel function in pytorch?
''' PyTorch torch.numel() method returns the total
number of elements in the input tensor.'''
# Importing the PyTorch library
import torch
# A constant tensor of size n
a = torch.randn(4, 6)
print(a)
# Applying the numel function and
# storing the result in 'out'
out = torch.numel(a)
print(out)
>>>-0.8263 0.9807 -1.4688 0.2117 -0.8356 -0.0228
-0.8815 1.3652 -0.1892 -1.1241 0.2755 1.3006
0.0559 0.2389 0.7944 2.6587 -2.0908 1.2973
-0.2056 0.4110 0.2163 0.3091 0.5559 -0.2468
[torch.FloatTensor of size 4x6]
24