+10 XP
NumPy Operations
The magic of NumPy: math on the whole array at once — no for loop needed.
python
import numpy as np
V = np.array([-70.0, -68.5, -55.0, 20.0, -70.0]) # voltages
# Math applies to EVERY element:
V + 10 # [-60. -58.5 -45. 30. -60. ]
V * 2 # [-140. -137. -110. 40. -140.]
# Statistics:
np.mean(V) # mean voltage
np.std(V) # standard deviation
np.max(V) # peak voltage (spike!)
# Boolean indexing — find spikes:
spike_mask = V > -55 # [False False False True False]
# Check each voltage: above threshold?
spike_V = V[spike_mask] # [20.0]
# Give me only the voltages where mask is TrueBoolean indexing is a filter. V[spike_mask] means: 'Extract only the elements where spike_mask is True'. This is how you find spikes in NMA — it's used constantly.
np.linspace(0, 1, 100) creates 100 evenly spaced points from 0 to 1. You'll use this for time arrays.