Preliminary Software Engineering
Unit 1 - Programming Fundamentals
Unit 1 - Programming Fundamentals
  • 1 - Programming Fundamentals
    • Programming Fundamentals Content
  • 2 - Python
    • Expected Python Knowledge
    • GitHub
    • Learning Python
    • Data Structures and File Management
      • Data Structures
        • Lists
        • Arrays
          • Single and Multi-Dimensional Arrays
        • Lists vs Arrays
          • Activities
        • Tuples
        • Sets
        • Dictionaries
          • Activities
      • File Handling
        • Loops, Lists, Dictionaries
        • Activities
  • 3 - Theory Content
    • Theory Content Explained
      • NESA Directional Verbs
      • Responding to Directional Verbs
  • 4 - Software Development and Management
    • Approaches to Software Development
      • Waterfall Model
      • Agile Model
      • Summary: Waterfall vs Agile
      • Activities
    • Software Development Steps
      • Sample Exam Question
      • Requirements Definition
        • Understanding the Need
        • Key Questions to Ask
        • Examples
        • Activities
        • Sample Exam Question
      • Determining Specifications
        • Functional Specifications
        • Non-Functional Specifications
        • Activities
      • Design
        • Top-Down Design Approach
        • Bottom-Up Design Approach
      • Development
        • Optimising Code
      • Integration
        • Example: Payment Program
        • Activity
        • Application Programming Interface (API)
          • Example: OpenWeather API
          • Example: WeatherAPI
          • Activity: Prepare Spells
      • Testing and Debugging
        • Test Data
          • Activities
        • Testing the System
          • Activities
        • Debugging
          • Types of Errors
            • Activities
          • Python Debugger
            • Activities
          • VS Code Debugger
            • Activities
      • Installation
        • Activities
        • Sample Exam Question
      • Maintenance
  • Charts and Algorithms
    • Example: IPO Charts and Pseudocode
      • Activities
    • Algorithms, Flowcharts, Pseudocode
      • Pseudocode Activities
      • Flowchart Activities
      • Sample Exam Questions
    • Structure Charts
      • Activities
      • Sample Exam Questions
    • Data Flow Diagrams
      • Activities
    • Data Dictionaries
      • Activities
    • Decision Trees
      • Activities
      • Sample Exam Questions
    • Gantt Chart
    • Class Diagrams
      • Sample Exam Question
    • Storyboards
      • Sample Exam Question
  • Testing and Debugging
    • Test Data
      • Activities
    • Testing the System
      • Activities
    • Debugging
      • Types of Errors
        • Activities
      • Python Debugger
        • Activities
      • VS Code Debugger
        • Activities
  • Computational Thinking
    • Decomposition
    • Abstraction
    • Activities
  • Version Control
    • Git
    • GitHub
    • Activities
  • Number Systems
    • Binary Systems
    • Hexadecimal Numbers
    • Using Two's Complement
    • Activities
  • 5 - Assessment Task 1
    • Data Science Project
      • Before we Start
        • Setting up GitHub Repository
        • Setting Up Markdown Documentation
      • Examples of API Usage
        • Starter Code: NASA Scenario
        • Starter Code: Spell Book
        • Starter: PokĂ©dex Explorer
        • Starter Code: Weather App
        • Example: OpenWeather API
        • Example: WeatherAPI
        • Example: Prepare Spells
    • Task Guide
      • Requirements Definition
      • Determining Specifications
        • Use Cases
      • Design
        • Gantt Chart
        • Structure Chart
        • Algorithms
        • Data Dictionary
      • Development
        • Comments vs DocStrings
        • UI - main.py
        • Create Python Module
          • Example: NASA Module
          • Example: WeatherFetch Module
          • Example: SpellBook Module
      • Integration
        • Example: Pokedex
      • Testing and Debugging
        • Commit Changes
      • Installation
      • Maintenance
    • Submitting Your Task
Powered by GitBook
On this page
  • Single-Dimensional Arrays
  • Example Using Array Module
  • Multi-Dimensional Arrays
  • Example Using NumPy Module
  • Key Differences
  1. 2 - Python
  2. Data Structures and File Management
  3. Data Structures
  4. Arrays

Single and Multi-Dimensional Arrays

PreviousArraysNextLists vs Arrays

Last updated 2 months ago

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

import array

# Creating a single-dimensional array of integers
numbers = array.array('i', [10, 20, 30, 40, 50])

# Accessing elements using their index
print(numbers[0])  # Output: 10
print(numbers[3])  # Output: 40

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:

[
  [1, 2, 3], 
  [4, 5, 6], 
  [7, 8, 9]
]

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.

import numpy as np

# Creating a 2D array (3 rows, 3 columns)
matrix = np.array([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
])

# Accessing elements using row and column indices
print(matrix[0][1])  # Output: 2 (row 0, column 1)
print(matrix[2][2])  # Output: 9 (row 2, column 2)

Key Differences

Feature
Single-Dimensional Array
Multi-Dimensional Array

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

2D Multidimensional Array