Courses / Physics I
Computer Science

Lists, arrays, and structured storage

Physics I 216 words Free to read

Physics simulations deal with collections of data: time series, particle positions, field values. Python provides lists and NumPy provides arrays.

Python lists — Ordered, mutable, can hold mixed types:

temperatures = [20.1, 21.3, 19.8, 22.0]
temperatures.append(23.5)       # add element
print(temperatures[0])          # → 20.1 (0-indexed)
print(len(temperatures))        # → 5

NumPy arrays — Homogeneous, fast, support vectorised operations:

import numpy as np

t = np.linspace(0, 10, 1000)      # 1000 points from 0 to 10
x = np.sin(2 * np.pi * t)         # element-wise sine

mean_x = np.mean(x)               # statistical operations

Why arrays over lists?

Slicing

data = np.array([10, 20, 30, 40, 50])
data[1:4]    # → [20, 30, 40]   (indices 1, 2, 3)
data[::2]    # → [10, 30, 50]   (every 2nd element)

Tip: Use np.array for numerical computation and Python list for heterogeneous or small collections. Never loop over array elements when a vectorised operation exists.
Common pitfall: Assigning a list copies a reference, not the data: after b = a, mutating b mutates a too. Deliberate copies (list(a), slicing) are how you actually fork data.

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

11practice questions
2interactive scenes
Start Physics I free

Computer Science