3 回答

TA贡献1851条经验 获得超5个赞
与numpy.convolve:
import numpy as np
arr = np.array([2,4,6,8,10,12,14,16,18])
n = 3
window = (1.0 / n) * np.ones(n,)
res = np.convolve(arr, window, mode='valid')[::n]
对于 2 x N 阵列:
from scipy import signal
arr = np.array([[2,4,6,8,10,12,14,16,18], [12,14,16,18,110,112,114,116,118]])
window = (1.0 / n) * np.ones((1, n))
#res = np.convolve(arr, window, mode='valid')[::n]
res = signal.convolve2d(arr, window, mode='valid')[:, ::n]

TA贡献1815条经验 获得超13个赞
def mean_pandas(your_df, start_roling=0, mean_roling = 3):
a = [df.iloc[:,range(i,i+mean_roling)].mean(axis=1) for i in range(start_roling,len(df),mean_roling) if i+mean_roling<=len(df)]
b = pd.DataFrame(np.array(a).T)
return b
mean_pandas(your_df, 0, 3)
添加回答
举报