+10 XP

From Single Neuron to Population

So far you've simulated one neuron. But the brain has billions. How do you handle that in code?

With 2D arrays — a grid of numbers, like a spreadsheet. Each row is a neuron. Each column is a time step.

python
import numpy as np

# Simulate 100 neurons for 1000 ms
V = np.random.normal(-70, 5, size=(100, 1000))
# V.shape = (100, 1000)
# Row 0: voltage of neuron 0 over all times
# Row 1: voltage of neuron 1 over all times
# Column j: voltage of all neurons at time j

print(V[0, 0])      # voltage of neuron 0 at time 0
print(V[0, :])      # voltage of neuron 0 across ALL times (spike train)
print(V[:, 100])    # voltage of ALL neurons at time 100
print(V.shape)      # (100, 1000)

A 2D array is indexed [neuron_index, time_index]. Use : to mean 'all'.

Why neuroscientists care:

In NMA, you often have population recordings — many neurons measured simultaneously. A calcium imaging video has 10,000 neurons × 10,000 time frames. How do you analyze it? With 2D arrays and vectorized operations.

python
# Real NMA example: calcium imaging data
# Shape: (n_neurons, n_time_frames)
F = calcium_recording  # shape (1000, 5000) — 1000 neurons, 5000 frames

# Find peak calcium (max response) for each neuron
peak_response = F.max(axis=1)  # max along time axis → (1000,)

# Find mean baseline (resting calcium) for each neuron
baseline = F.mean(axis=1)  # mean along time axis → (1000,)

# Compute stimulus-evoked response
response = peak_response - baseline  # (1000,)

print(f'Average response across population: {response.mean()}')

axis=0 means collapse down columns (operate per-neuron). axis=1 means collapse across rows (operate per-time).