9951 explained code solutions for 126 technologies


python-tensorflowHow can I determine the size of a Python Tensorflow package?


To determine the size of a Python Tensorflow package, you can use the sys.getsizeof() method. This method returns the size of an object in bytes.

For example:

import sys
import tensorflow as tf

x = tf.random.normal([2, 2])

print(sys.getsizeof(x))

Output example

128

The code above imports the sys and tensorflow modules, then creates a random normal tensor of size 2x2 using tf.random.normal(). Finally, it uses sys.getsizeof() to determine the size of the tensor, which is 128 bytes.

Helpful links

Edit this code on GitHub