/Curriculum/BeginnerArray Basics

02. NumPy Arrays (ndarray)Beginner

Master 1D vectors, 2D matrices, and 3D tensors built on NumPy's ndarray object.

12 mins

Concept Overview

The core data structure in NumPy is the 'ndarray' (N-dimensional array). It represents a multi-dimensional table of elements of the same type, indexed by a tuple of positive integers.

Hardware Mental Model

1D is a row of mailboxes (vector). 2D is a postal sorting grid with rows and columns (matrix). 3D is a tall cabinet holding multiple shelves of grids (tensor).

Key Concepts (1)Click snippet to load in editor

1D arrays have 1 axis (length). 2D arrays have 2 axes: axis 0 (rows) and axis 1 (columns).

matrix = np.array([[1, 2], [3, 4]])

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:arr = np.array(1, 2, 3)
✓ Correct:arr = np.array([1, 2, 3])

Elements must be passed as a single list `[1, 2, 3]` or tuple inside `np.array()`.

Pro Tip: Always wrap your numbers inside square brackets `np.array([...])`.

📌 Quick Revision

Core takeaway points from this topic
1D arrays have shape `(N,)` and ndim = 1.
2D arrays have shape `(Rows, Cols)` and ndim = 2.
3D arrays have shape `(Depth, Rows, Cols)` and ndim = 3.
Editor: 02. NumPy Arrays (ndarray)
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:Create a 2x2 Matrix

Create a 2D matrix containing `[[1, 2], [3, 4]]` and print it.

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