且构网

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

仅沿一个轴进行卷积

更新时间: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.