【发布时间】:2020-06-24 13:09:08
【问题描述】:
我想像在 1D 中一样使用 2D 卷积。不幸的是,前一种情况下的输出没有所需的形状。让n = 5,然后
h_0 = (1 / 4) * np.array([1, 2, 1])
x = np.random.rand(n)
np.convolve(h_0, x, 'same')
>>> array([0.65498075, 0.72729356, 0.51417706, 0.34597679, 0.1793755])
但是
h_00 = np.kron(h_0, h_0)
h_00 = np.reshape(h_00, (3, 3))
x = np.random.rand(n, n)
scipy.signal.convolve2d(h_00, x, 'same', boundary='symm')
>>> array([[1.90147294, 1.6541233 , 1.82704077],
[1.55228912, 1.3641027 , 1.55536069],
[1.61190909, 1.45159935, 1.58266083]])
我本来希望有一个(5, 5) 输出数组。
【问题讨论】:
-
a的大小为 5 - 输出 5;h_00的形状为(3, 3)输出的形状为(3, 3)。一切似乎都合理? -
@V.Ayrat 我希望输出取决于
x的大小(形状)。
标签: python arrays numpy scipy convolution