Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

size of variable in python

I would like to know how much memory is being occupied by a variable.

Let us assume this example:

import numpy as np

t = [np.random.rand(10000) for _ in range(1000)]

How much memory in megabytes is t occupying?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I ran:

sys.getsizeof(array_list)

and I am getting 8856 which seems low for the amount of information contained in t

Best Regards.

>Solution :

from pympler import asizeof
asizeof.asizeof([np.random.rand(10000) for _ in range(1000)])

#output
80120872

Link : https://pypi.org/project/Pympler/

pip install Pympler
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading