/Curriculum/BeginnerArray Basics

03. NumPy Array AttributesBeginner

Inspect ndim, shape, size, dtype, itemsize, nbytes, and strides memory layout.

10 mins

Concept Overview

Every ndarray contains metadata attributes that tell you its geometry, element data types, and how bytes are stepped across in memory.

Hardware Mental Model

Think of attributes as an array's passport: shape tells you its dimensions, dtype tells you element weight, and strides tell the CPU how many bytes to jump.

Key Concepts (1)Click snippet to load in editor

arr.shape is a tuple of dimension lengths; arr.size is total elements; arr.strides is the number of bytes to step in memory along each axis.

shape = arr.shape; strides = arr.strides

Interactive 3D Tensor Cube Visualizer

shape: (3, 3, 3)

Visualize multidimensional ndarrays in full 3D space with depth, row, and column slice planes.

Rotate X: -22° • Rotate Y: 35°
Choose Tensor Slice Plane:
Layer Explosion Gap:30px
Rotate Horizontal Angle:35°
Python Slicing Syntax:tensor = np.arange(10, 37).reshape(3, 3, 3)

Full 3D ndarray Tensor. Shape: (3, 3, 3) • 27 elements in RAM

⚠ Common Mistakes & Pitfalls

Avoid these frequent beginner syntax and logic traps
❌ Incorrect:print(arr.shape())
✓ Correct:print(arr.shape)

shape, ndim, and size are properties/attributes, not callable functions.

Pro Tip: Never add parentheses `()` after `.shape`, `.ndim`, or `.dtype`.

📌 Quick Revision

Core takeaway points from this topic
`ndim`: Number of array dimensions.
`shape`: Tuple of dimension lengths (e.g. `(2, 3)`).
`size`: Total element count.
`nbytes`: Total memory consumed in bytes.
Editor: 03. NumPy Array Attributes
Python ● Ready
Initializing Python IDE...
Ctrl+Enter
Execution Result
Click "RUN CODE" to execute and inspect array state

🎯 Try It Yourself: Practice Challenge

Hands-on Mode

Solve the objective below using NumPy vectorized syntax

Objective:Query Array Shape

Create an array `arr = np.array([[1, 2, 3], [4, 5, 6]])` and print `arr.shape`.

Expected Output Target:(2, 3)
Practice Workspace
Python ● Ready
Initializing Python IDE...
Ctrl+Enter
Execution Result
Click "RUN CODE" to execute and inspect array state