Reputation: 1278
I just want the number of elements in my tensor, regardless of shape.
I see in the documentation num_elements
serves my purpose. However, if I try to use it as myTensor.num_elements()
, I get this error:
AttributeError: 'Tensor' object has no attribute 'num_elements'
How do I do this?
Upvotes: 0
Views: 672
Reputation: 4475
This method belongs to TensorShape
instead of Tensor
. You can get the number of elements like this
import tensorflow as tf
a = tf.random.uniform((1,16,23))
a.shape.num_elements()
# 368
Upvotes: 1