How does a short convolution kernel yield full-window rolling sums?

One-dimensional convolve computes discrete linear convolution. With an all-ones kernel, full overlaps yield window sums.

numpy.convolve in practice

A length-two kernel over [2,4,1] yields six and five for complete windows. An asymmetric kernel is reversed by convolution, which matters when weights have a preferred direction.

import numpy as np
np.convolve([2,4,1],[1,1],mode='valid')

Result [6, 5]

中文

如何用短卷积核得到完整窗口的滑动和?

一维 convolve 计算离散线性卷积。对全一核,每个完全重叠位置给出一个窗口和。

numpy.convolve 算例

长度为二的核滑过 [2,4,1],两个完整窗口分别得 6 和 5。非对称核在卷积中有翻转,不能一概当作逐项按原序加权。

import numpy as np
np.convolve([2,4,1],[1,1],mode='valid')

结果 [6, 5]

References / 参考来源

Keep reading / 继续阅读