amep.utils.average_func#
- amep.utils.average_func(func: callable, data: list | ndarray, skip: float = 0.0, nr: int = 10, indices: bool = False, **kwargs)#
Compute the average of a certain function.
- Parameters:
func (func) – function that has to be averaged
data (list/np.ndarray) – list/array of data for each time step (input for func)
skip (float, default=0.0) – fraction of the whole trajectory that is skipped at the beginning of the trajectory for the calculation of the time average (float between 0.0 and 1.0)
nr (int, default=10) – maximum number of frames to average over
indices (bool, default=False) – If True, the list indices that the averaging function used are returned as last output!
**kwargs (Keyword Arguments) – keyword arguments that are put to func
- Returns:
list – list of func results for each time step
various – time-averaged value of func for given trajectory
Examples
>>> import amep >>> import numpy as np >>> def function(x): ... return x**2 >>> x = np.linspace(0,100,1000) >>> y = np.sin(x) >>> function_yvalues, average = amep.utils.average_func( ... function, y, nr=20 ... ) >>> function_xvalues, _ = amep.utils.average_func( ... lambda x:x, x, nr=20 ... ) >>> fig, axs = amep.plot.new() >>> axs.plot( ... function_xvalues, function_yvalues, ... label='data' ... ) >>> axs.axhline(average, label='average', ls='--') >>> axs.legend() >>> axs.set_xlabel(r'$x$') >>> axs.set_ylabel(r'$y$') >>> fig.savefig('./figures/utils/utils-average_func.png') >>>