def convolve(x, f):
from numpy import fft, all
sx = numpy.array(x.shape)
sf = numpy.array(f.shape)
if not all(sx >= sf): return convolve(f, x)
y = fft.ifftn(fft.fftn(x) * fft.fftn(f, sx)).real
slices = [slice(sf[i] - 1, sx[i]) for i in range(len(sf))]
return y[slices]
评论列表
文章目录