nbytes
nbytes is the total memory the array's data occupies.
In this page:
Syntax
arr.nbytes # size * itemsize
nbytes
nbytes equals size multiplied by itemsize. It counts only the element data, not the small array object overhead. It is a quick way to estimate how much RAM a large array will use.
Note:
A million float64 values take about 8 MB.
Example: nbytes
import numpy as np
a = np.zeros(1000, dtype=np.float64)
b = np.zeros(1000, dtype=np.float32)
print(a.nbytes, b.nbytes)
print(a.size * a.itemsize == a.nbytes)
# Output:
# 8000 4000
# True
Related Topics
Common Mistakes
- Expecting nbytes to include Python object overhead
- Forgetting dtype affects the total
- Comparing with sys.getsizeof which reports differently
Chapter Summary
- nbytes = size * itemsize
- Only counts element data
- Halving precision halves memory
- Useful for capacity planning