Python:NumPy .itemsize
Published Oct 30, 2025
Contribute to Docs
The .itemsize attribute of a NumPy ndarray returns the number of bytes used to store each element in the array, as determined by the array’s dtype.
Syntax
ndarray.itemsize
Parameters:
This attribute does not take any parameters.
Return value:
Returns an integer that represents the number of bytes used to store each element in the array, based on its data type (dtype).
Example
In this example, arrays with different data types return different byte sizes per element when accessed through the .itemsize attribute:
import numpy as nparr_int32 = np.array([1, 2, 3], dtype=np.int32)arr_float64 = np.array([1.0, 2.0, 3.0], dtype=np.float64)arr_int8 = np.array([1, 2, 3], dtype=np.int8)print(arr_int32.itemsize) # 4 bytes per elementprint(arr_float64.itemsize) # 8 bytes per elementprint(arr_int8.itemsize) # 1 byte per element# Equal to dtype.itemsizeprint(arr_int32.itemsize == arr_int32.dtype.itemsize)
This produces output similar to:
481True
Codebyte Example
In this example, the .itemsize attribute is used to inspect the memory size of elements for different NumPy dtypes:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:NumPy on Codecademy
- Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
- Includes 27 Courses
- With Professional Certification
- Beginner Friendly.95 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours