Skip to content

Instantly share code, notes, and snippets.

@kiurtis
Last active March 14, 2021 14:25
Show Gist options
  • Save kiurtis/b3c569a681efeeca0ef0877724310a04 to your computer and use it in GitHub Desktop.
Save kiurtis/b3c569a681efeeca0ef0877724310a04 to your computer and use it in GitHub Desktop.
#### Get all the numpy array and their size ####
# From https://stackoverflow.com/questions/11784329/python-memory-usage-of-numpy-arrays
import sys
import numpy
from humanize import naturalsize
for size, name in sorted(
(value.nbytes, name)
for name, value in locals().items()
if isinstance(value, np.ndarray)):
print("{:>30}: {:>8}".format(name, naturalsize(size)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment