amep.utils.runningmean#
- amep.utils.runningmean(data: ndarray, nav: int, mode: str = 'valid') ndarray #
Compute the running mean of a 1-dimensional array.
- Parameters:
data (np.ndarray) – input data of shape (N, )
nav (int) – number of points over which the data will be averaged
mode (str) – ‘same’, ‘valid’, or ‘full’
- Returns:
averaged data
- Return type:
np.ndarray of shape (N-(nav-1), )
Examples
>>> import amep >>> import numpy as np >>> x = np.linspace(0,2*np.pi,500) >>> y = np.sin(x)*(1+np.random.rand(len(x))) >>> yav = amep.utils.runningmean(y, nav=20) >>> xav = amep.utils.runningmean(x, nav=20) >>> fig, axs = amep.plot.new() >>> axs.plot(x, y, label='data', ls='') >>> axs.plot( ... xav, yav, label='running mean', ... marker='', lw=2, c='orange' ... ) >>> axs.legend() >>> axs.set_xlabel(r'$x$') >>> axs.set_ylabel(r'$y$') >>> fig.savefig('./figures/utils/utils-runningmean.png') >>>