Python Practice › NumPy Programs › Program 13
Memory used by an array
Write a NumPy program to find the memory occupied by an array.
Output
5 8 40
Approach
nbytes= number of items × bytes per item.
Solution
import numpy as nparr = np.array([10, 34, 86, 26, 56], dtype=np.int64)print(arr.size, arr.itemsize, arr.nbytes)Output
5 8 40
Line by line
Line 2
The dtype is fixed to int64 so the size is the same on every platform.
Learn the concept
New to this topic? Read the lesson, then come back.