Skip to content Skip to sidebar Skip to footer

Nbytes And Getsizeof Return Different Values

I have noticed that nbytes and getsizeof returns two different values when the bank to a NumPy array. Example: import sys import numpy as np x = np.random.rand(10000, 50) print('x.

Solution 1:

This is because nbytes only returns the size of stored data, while sys.getsizeof returns the size of the whole object, i.e. the size of the stored data plus some overhead. There is a small overhead for numpy arrays, because they have to store the array dimensions, the datatype and similar information.


Post a Comment for "Nbytes And Getsizeof Return Different Values"