Single and Multi-Dimensional Arrays
Last updated
Last updated
A single-dimensional array is a linear collection of elements, meaning it has only one row of data. Each element is accessed using a single index.
Think of it like a list of numbers in a straight line:
Each item in this array is accessed using a single index.
A multi-dimensional array is an array containing other arrays inside it. The most common type is a 2D array, which resembles a table with rows and columns.
For example, a 2D array can be visualised as:
Each element is accessed using two indices: one for the row and one for the column.
Python’s built-in array
module only supports single-dimensional arrays, so we use NumPy for multi-dimensional arrays.
Structure
A single row of elements
A grid (rows and columns)
Indexing
Uses one index (e.g., arr[2]
)
Uses multiple indices (e.g., arr[1][2]
)
Usage
Used for simple lists of data
Used for tables, matrices, images, etc.
Library
Can use array
module or lists
Requires numpy
for efficient handling