Files
Mastering-Python-2e-code_2/CH_15_scientific_python/T_02_scipy.rst
T
2022-05-05 18:25:55 +02:00

21 lines
429 B
ReStructuredText

>>> import numpy
>>> from scipy import sparse
>>> x = numpy.identity(10000)
>>> y = sparse.identity(10000)
>>> x.data.nbytes
800000000
# Summing the memory usage of scipy.sparse objects require summing
of all internal arrays. We can test for these arrays using the
nbytes attribute.
>>> arrays = [a for a in vars(y).values() if hasattr(a, 'nbytes')]
# sum the bytes from all arrays
>>> sum(a.nbytes for a in arrays)
80004