[英]Circular convolution in python
Is there a way with Python to perform circular convolution between two 1D arrays, like with Matlab function cconv
? 有没有办法用Python在两个1D数组之间执行循环卷积,就像Matlab函数cconv
? I tried numpy.convolve
but it isn't the same, and I can't find an equivalent. 我试过numpy.convolve
但它不一样,我找不到相应的东西。
You can try this command : scipy.ndimage.filters.convolve1d 您可以尝试以下命令: scipy.ndimage.filters.convolve1d
You have an option which is named mode
and you can write mode = wrap
你有一个名为mode
的选项,你可以写mode = wrap
With that, you get periodic boundary conditions as padding for the convolution 这样,您可以获得周期性边界条件作为卷积的填充
For example : 例如 :
result = scipy.ndimage.convolve(image,kernel,mode='wrap')
import numpy as np
image = np.array([[0, 0, 0, 0],
[0, 0, 0, 1],
[0, 0, 0, 0]])
kernel = np.array([[1, 1, 1],
[1, 1, 1],
[1, 1, 1]])
from scipy.ndimage import convolve
convolve(image, kernel, mode='wrap')
array([[1, 0, 1, 1],
[1, 0, 1, 1],
[1, 0, 1, 1]])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.