+10 XP

2D NumPy Arrays

Python lists work. NumPy arrays are what scientists actually use — 100× faster and support powerful operations like axis-based statistics and vectorized math.

Key functions:
np.zeros(n) — 1D array of n zeros
np.zeros((N, T)) — 2D array: N rows, T columns
arr[i, j] — row i, column j
arr[:, j] — all rows at column j
arr[i, :] — all columns of row i

python
import numpy as np
# 2D array for N neurons × T timesteps
N, T = 5, 10
np.zeros((N, T)): N rows (neurons), T columns (time)
V = np.zeros((N, T))
V[:, 0]: ALL rows, column 0 — set every neuron's initial V
V[:, 0] = -60e-3  # all neurons start at resting potential
print(f"V shape: {V.shape}")
print(f"V[0, :3] = {V[0, :3]*1000} mV  (neuron 0, first 3 steps)")
V[0, :3]: row 0, first 3 columns
print(f"V[:, 0] = {V[:, 0]*1000} mV  (all neurons at t=0)")

Convention: V[neuron_index, time_index]. Row = which neuron, column = which time step.

np.arange(start, stop, step) is like range() but returns a NumPy array of floats:
t = np.arange(0, 150e-3, 1e-3) → array of 150 time values from 0 to 149 ms.