功能是什么func
计算 n-1
-大小数组的后续元素的平均值数组 n
(即窗口宽度为 2 的移动平均线)?
func(numpy.array([1,2,3,4,5]))
# return numpy.array([1.5, 2.5, 3.5, 4.5])
最佳答案
这里不需要函数:
import numpy as np
x = np.array([1,2,3,4,5])
x_f2 = 0.5*(x[1:] + x[:-1])
如果你想把它作为一个函数:
def window(x, n):
return (x[(n-1):] + x[:-(n-1)])/float(n)
关于numpy - 邻居平均值数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10849054/