← Lab 5

Two dimensions, and no more loops

Stack 254 single trials into one table, average down the columns, and find out what this neuron is actually for — then find out why numpy is worth the trouble.

The second dimension
  • ▸np.stack — a list of trials becomes a table
  • ▸shape as (rows, columns) = (trials, frames)
  • ▸trials[row, col] — and : for a whole column
  • ▸axis=0 vs axis=1 — which dimension disappears
Vectorisation
  • ▸the same job as a loop, in one line
  • ▸time it yourself — tens of times faster
  • ▸broadcasting, and the shape error you will hit
  • ▸baseline-correct 254 trials without a loop
Python for Biologists