def ma(x, win):
"""Compute the moving average of x with a window equal to win
Args:
x (numpy.array): data
win (int): window
Returns:
numpy.array: the smoothed data
"""
y = np.ones(win, dtype=np.float64)
i = win - 1
_x = np.convolve(x, y, mode='full')[:-i]
_x[1:i] = _x[1:i] / np.arange(2., win, dtype=np.float64)
_x[i:] = _x[i:] / float(win)
return _x
评论列表
文章目录