Arrays - what are they and multiple dimensions
NumPy - The Basics
2 min read
This section is 2 min read, full guide is 14 min read
Published Sep 22 2025
11
Show sections list
0
Log in to enable the "Like" button
0
Guide comments
0
Log in to enable the "Save" button
Respond to this guide
Guide Sections
Guide Comments
NumPyPython
What is a NumPy Array?
- A NumPy array (
ndarray
) is a grid of values (all of the same data type), stored in contiguous memory. - Unlike Python lists, arrays are:
- Faster (implemented in C, vectorised operations).
- Memory efficient (fixed data type, compact storage).
- Support broadcasting and mathematical operations directly.
Think of it as a supercharged list designed for math and data manipulation.
Array Dimensions (Rank)
- The number of axes (dimensions) an array has is called its rank.
- NumPy arrays can be 1D, 2D, 3D, … nD.
1D Array (Vector)
A simple sequence of numbers (like a list):
import numpy as np
arr1d = np.array([10, 20, 30, 40])
print(arr1d.shape)
# (4,)
Copy to Clipboard
Toggle show comments
Looks like: [10, 20, 30, 40]
2D Array (Matrix)
Rows and columns:
arr2d = np.array([[1, 2, 3],
[4, 5, 6]])
print(arr2d.shape)
# (2, 3)
Copy to Clipboard
Toggle show comments
Looks like:
[[1 2 3]
[4 5 6]]
3D Array (Tensor / Cube)
A stack of 2D arrays:
arr3d = np.array([[[1, 2], [3, 4]],
[[5, 6], [7, 8]]])
print(arr3d.shape)
# (2, 2, 2)
Copy to Clipboard
Toggle show comments
Think of it as 2 layers, each with 2 rows and 2 columns.
Higher Dimensions
- NumPy supports n-dimensional arrays (
ndarray
). - Example: a 4D array could represent multiple 3D datasets (useful in deep learning, images, video frames, etc.).
Key Attributes of Arrays
Every NumPy array has:
.ndim
→ number of dimensions..shape
→ size along each dimension (tuple)..size
→ total number of elements..dtype
→ data type of elements.
print(arr2d.ndim)
# 2 (2D array)
print(arr2d.shape)
# (2, 3) → 2 rows, 3 columns
print(arr2d.size)
# 6 (total elements)
print(arr2d.dtype)
# int64 (depends on system)
Copy to Clipboard
Toggle show comments
Why Multi-Dimensional Arrays?
- 1D → simple sequences (signals, series, vectors).
- 2D → tables, matrices (spreadsheets, images).
- 3D → stacked data (colour images with RGB channels, cubes).
- nD → higher-order data (video, deep learning tensors).