Single and Multi-Dimensional Arrays
Single-Dimensional Arrays
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:
[10, 20, 30, 40, 50]Each item in this array is accessed using a single index.

Example Using Array Module
Multi-Dimensional Arrays
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.

Example Using NumPy Module
Python’s built-in array module only supports single-dimensional arrays, so we use NumPy for multi-dimensional arrays.
Key Differences
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
Last updated