Skip to main content
Albero Academy

Array Attributes

Inspect any array with shape, ndim, size, dtype, itemsize and nbytes.

Foundations7 min

Before operating on an array, you inspect it. Every ndarray exposes a handful of attributes that tell you its structure and memory footprint — the first things you check when a shape mismatch or memory issue appears.

The key attributes

AttributeMeaning
ndimNumber of dimensions (axes)
shapeSize along each axis, e.g. (2, 3)
sizeTotal number of elements
dtypeElement type
itemsizeBytes per element
nbytesTotal bytes (size × itemsize)
inspecting an array
a = np.zeros((3, 4), dtype=np.float64)
a.ndim # 2
a.shape # (3, 4)
a.size # 12
a.itemsize # 8 (float64 = 8 bytes)
a.nbytes # 96 (12 × 8)

Shape is your debugger

Key takeaways

  1. 01ndim, shape and size describe an array's structure.
  2. 02dtype, itemsize and nbytes describe its memory footprint.
  3. 03nbytes = size × itemsize — how to estimate an array's RAM cost.
  4. 04Check .shape first when debugging — most NumPy bugs are shape mismatches.

Finished this chapter?

Mark it complete to track your progress through NumPy.