Python:NumPy .itemsize

hRITHIKSAWHNEY7748311119's avatar
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.

  • 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

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 np
arr_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 element
print(arr_float64.itemsize) # 8 bytes per element
print(arr_int8.itemsize) # 1 byte per element
# Equal to dtype.itemsize
print(arr_int32.itemsize == arr_int32.dtype.itemsize)

This produces output similar to:

4
8
1
True

Codebyte Example

In this example, the .itemsize attribute is used to inspect the memory size of elements for different NumPy dtypes:

Code
Output
Loading...

All contributors

Contribute to 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