Topics in this subject
NumPy 1 min read Updated 4 Aug 2026

3. Array Attributes

Every attribute below is a cheap header read — no computation over the data.

Every attribute below is a cheap header read — no computation over the data.

Attribute Meaning Example value
.shape tuple of dimension sizes (2, 3)
.size total number of elements 6
.ndim number of dimensions 2
.dtype element type int64
.itemsize bytes per element 8
.nbytes total bytes = size * itemsize 48
.strides bytes to step per axis (24, 8)
.flags memory layout flags (C/F contiguous, writeable, owns data)
.base the array this is a view of (None if it owns its data)
.T transposed view
a = np.arange(6).reshape(2, 3)
print(a.shape, a.size, a.ndim)       # (2, 3) 6 2
print(a.dtype, a.itemsize, a.nbytes) # int64 8 48
print(a.strides)                     # (24, 8)
print(a.T.shape)                     # (3, 2)

v = a[0]           # a slice/view
print(v.base is a) # True  -> v is a view onto a

📌 Remember: If x.base is not None, x is a view — writing to x mutates the parent array. This is the #1 source of "why did my other array change?" bugs.

Interview Question: What are strides? The number of bytes to jump in memory to move one step along each axis. Reshapes/transposes work by rewriting strides, avoiding data copies.