fn
numel
→intnumel(x: Tensor)Return the total number of elements in a tensor.
Equivalent to the product of the shape dimensions, returned as a
plain Python int so it can be used in pure-Python control flow
(loops, conditionals) without triggering autograd tracing.
Parameters
xTensorInput tensor.
Returns
intTotal number of scalar elements: .
Notes
For a tensor of shape :
A 0-D (scalar) tensor has numel == 1; a tensor with any dimension
of size 0 has numel == 0.
Examples
>>> import lucid
>>> x = lucid.zeros((2, 3, 4))
>>> lucid.numel(x)
24