I have two scipy matrices 'a' and 'b' with boolean values in them. 'a' is way bigger than 'b': 765565 values against just 3 values.
In [211]: a
Out[211]: <388839x8455 sparse matrix of type '<class 'numpy.bool_'>'
with 765565 stored elements in Compressed Sparse Row format>
In [212]: b
Out[212]: <5x3 sparse matrix of type '<class 'numpy.bool_'>'
with 3 stored elements in Compressed Sparse Row format>
But when I check their sizes in terms of memory usage, I see that they are both just 56 bytes:
In [213]: from sys import getsizeof
'Size of a: {}. Size of b: {}'.format(getsizeof(a), getsizeof(b))
Out[213]: 'Size of a: 56. Size of b: 56'
How come these matrices' sizes are the same, while matrix 'a' has to store over 200 thousand times more values than matrix 'b'?
getsizeofReturn the size of an object in bytes. The object can be any type of object. All built-in objects will return correct results, but this does not have to hold true for third-party extensions as it is implementation specific.a.data.nbytesworks in this case.a.indptr.nbytes + a.indices.nbytes