且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Numpy/Scipy中的卷积计算

更新时间:2022-04-05 05:39:18

所以我对此进行了测试,现在可以确认一些事情:

So I tested this out and can now confirm a few things:

1)numpy.convolve不是循环的,这是fft代码为您提供的:

1) numpy.convolve is not circular, which is what the fft code is giving you:

2)FFT在内部没有填充2的幂.比较以下操作的速度差异很大:

2) FFT does not internally pad to a power of 2. Compare the vastly different speeds of the following operations:

x1 = np.random.uniform(size=2**17-1)
x2 = np.random.uniform(size=2**17)

np.fft.fft(x1)
np.fft.fft(x2)

3)归一化没什么不同-如果通过将a(k)* b(i-k)加起来进行朴素的圆卷积,您将获得FFT代码的结果.

3) Normalization is not a difference -- if you do a naive circular convolution by adding up a(k)*b(i-k), you will get the result of the FFT code.

填充2的幂将改变答案.我听说过一些故事,有一些方法可以通过巧妙地使用长度的素数来解决这一问题(提到但未在《数字食谱》中进行编码),但我从未见过有人真正这样做过.

The thing is padding to a power of 2 is going to change the answer. I've heard tales that there are ways to deal with this by cleverly using prime factors of the length (mentioned but not coded in Numerical Recipes) but I've never seen people actually do that.