elephant.statistics.mean_firing_rate¶
- elephant.statistics.mean_firing_rate(spiketrain, t_start=None, t_stop=None, axis=None)[source]¶
Return the firing rate of the spike train.
The firing rate is calculated as the number of spikes in the spike train in the range [t_start, t_stop] divided by the time interval t_stop - t_start. See the description below for cases when t_start or t_stop is None.
Accepts a neo.SpikeTrain, a pq.Quantity array, or a plain np.ndarray. If either a neo.SpikeTrain or pq.Quantity array is provided, the return value will be a pq.Quantity array, otherwise a plain np.ndarray. The units of the pq.Quantity array will be the inverse of the spiketrain.
- Parameters:
- spiketrainneo.SpikeTrain or pq.Quantity or np.ndarray
The spike times.
- t_startfloat or pq.Quantity, optional
The start time to use for the interval. If None, retrieved from the t_start attribute of spiketrain. If that is not present, default to 0. All spiketrain’s spike times below this value are ignored. Default: None
- t_stopfloat or pq.Quantity, optional
The stop time to use for the time points. If not specified, retrieved from the t_stop attribute of spiketrain. If that is not present, default to the maximum value of spiketrain. All spiketrain’s spike times above this value are ignored. Default: None
- axisint, optional
The axis over which to do the calculation; has no effect when the input is a neo.SpikeTrain, because a neo.SpikeTrain is always a 1-d vector. If None, do the calculation over the flattened array. Default: None
- Returns:
- float or pq.Quantity or np.ndarray
The firing rate of the spiketrain
- Raises:
- TypeError
If the input spiketrain is a np.ndarray but t_start or t_stop is pq.Quantity.
If the input spiketrain is a neo.SpikeTrain or pq.Quantity but t_start or t_stop is not pq.Quantity.
- ValueError
If the input spiketrain is empty.
Examples
>>> from elephant import statistics >>> statistics.mean_firing_rate([0.3, 4.5, 6.7, 9.3]) 0.4301075268817204