pynapple.core.time_series.TsdTensor.bin_average#
- TsdTensor.bin_average(bin_size, ep=None, time_units='s')#
Bin the data by averaging points within bin_size bin_size should be seconds unless specified. If no epochs is passed, the data will be binned based on the time support.
- Parameters:
bin_size (float) – The bin size (default is second)
ep (None or IntervalSet, optional) – IntervalSet to restrict the operation
time_units (str, optional) – Time units of bin size (‘us’, ‘ms’, ‘s’ [default])
- Returns:
out – A Tsd object indexed by the center of the bins and holding the averaged data points.
- Return type:
Examples
This example shows how to bin data within bins of 0.1 second.
>>> import pynapple as nap >>> import numpy as np >>> tsd = nap.Tsd(t=np.arange(100), d=np.random.rand(100)) >>> bintsd = tsd.bin_average(0.1)
An epoch can be specified:
>>> ep = nap.IntervalSet(start = 10, end = 80, time_units = 's') >>> bintsd = tsd.bin_average(0.1, ep=ep)
And bintsd automatically inherit ep as time support:
>>> bintsd.time_support >>> start end >>> 0 10.0 80.0