0 / 34
Lesson 2

Array Properties

Every array carries metadata:

  • .shape โ€” dimensions as a tuple
  • .dtype โ€” data type
  • .ndim โ€” number of dimensions
a = np.array([[1, 2], [3, 4]])
print(a.shape)  # (2, 2)
print(a.dtype)  # int64
print(a.ndim)   # 2
Why this matters

shape, dtype, and ndim are how libraries agree on memory layout. Wrong expectations here cause silent bugs when you stack, save, or pass arrays into C/Fortran-backed code.

Diagram of a 2D array with shape tuple, dtype label, and ndim callout.
Metadata is the contract between your data and every function that consumes it.

Getting comfortable reading these three fields makes errors like "operands could not be broadcast" much easier to debug.

ResourcesDocs, references & more โ€” opens in a new tab
๐ŸŽฏ Your Task

Create a 2D array matrix with shape (2, 3). Print its shape, dtype, and ndim.

np.array([[1,2,3],[4,5,6]])
exercise.py
โŒ˜โŽ run ยท โŒ˜โ† โ†’ nav
โ–ถ Output
Run your code to see output here.