Arrays - what are they and multiple dimensions

NumPy - The Basics

2 min read

Published Sep 22 2025


11
0
0
0

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,)

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)

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)

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)




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).

Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact