I am trying to determine the sizes of different data types in python, and wrote the following code. Each line's outputs are shown as comments beside them.
import numpy as np
import sys
print(sys.version) # 3.6.7
print(np.version.version) # 1.15.4
i = 2
print(type(i)) # <class 'int'>
print(sys.getsizeof(i)) # 28
j = np.int64(3)
print(type(j)) # <class 'numpy.int64'>
print(sys.getsizeof(j)) # 32
a = np.array([[1,2],[3,4],[5,6]])
print(type(a)) # <class 'numpy.ndarray'>
print(sys.getsizeof(a)) # 160
print(type(a[0][0])) # <class 'numpy.int64'>
print(sys.getsizeof(a[0][0])) # 32
a = np.array([[1,2],[3,4],[5,6],[7,8]])
print(sys.getsizeof(a)) # 176
From the above outputs, size of a 6 element array is 160 and size of a 8 element array is 176, so can I conclude that size of each element in the array is 8 bytes and the size of the array's header (constant) is 112 bytes? Is the size of each element constant or depends on its value (large or small)?
Also, when I am printing the size of a[0][0] why am I getting 32 and not 8? What exactly is the maths behind python and numpy integers and arrays?
a[0][0]is also anumpy.ndarray. Why not expect 120?