NumPy | itemsize property
Start your free 7-days trial now!
itemsize property returns the memory size of the array's data-type in bytes.
a = np.array([1,2,3], dtype="int64")a.itemsize8
Here, the contents in the array are irrelevant - only the data-type is important here. We set the datatype of the array as "int64", which means that each item in the array will be 8 bytes (i.e. 64 bits). This is exactly what the output is telling us.
To drive home the concept, consider the following:
a = np.array([1,2,3], dtype="int32")a.itemsize4
Here, 32-bit integer corresponds to 4 bytes, and so that's what is returned.