更新时间:2023-02-02 15:33:49
您可以使用np.apply_along_axis
沿所需的轴应用np.convolve
.这是将Boxcar滤镜应用于2d数组的示例:
You can use np.apply_along_axis
to apply np.convolve
along the desired axis. Here is an example of applying a boxcar filter to a 2d array:
import numpy as np
a = np.arange(10)
a = np.vstack((a,a)).T
filt = np.ones(3)
np.apply_along_axis(lambda m: np.convolve(m, filt, mode='full'), axis=0, arr=a)
这是一种概括许多没有axis
参数的函数的简便方法.
This is an easy way to generalize many functions that don't have an axis
argument.