Weighted moving average in python

前端 未结 2 1063
有刺的猬
有刺的猬 2020-12-08 08:03

I have data sampled at essentially random intervals. I would like to compute a weighted moving average using numpy (or other python package). I have a crude implementation o

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 09:05

    You could use numpy.average which allows you to specify weights:

    >>> bin_avg[index] = np.average(items_in_bin, weights=my_weights)
    

    So to calculate the weights you could find the x coordinates of each data point in the bin and calculate their distances to the bin center.

提交回复
热议问题