看代码看见这个方法,记录一下,这个是人家官网的链接np.correlate
云里雾里的,其实就是两个数组点乘,不同模式就是错位点乘,直接看代码
a是原本的数组,v就是滤波器,对应相乘
import numpy as np
mode0 = 'same'
mode1 = 'valid'
mode2 = 'full'
a = [1, 2, 3]
v = [1, 2]
print(np.correlate(a, v, mode0))
print(np.correlate(a, v, mode1))
print(np.correlate(a, v, mode2))
# 结果
[2 5 8]
[5 8]
[2 5 8 3]
a = [1, 2, 3]
v = [1, 2, 3]
print(np.correlate(a, v, mode0))
print(np.correlate(a, v, mode1))
print(np.correlate(a, v, mode2))
# 结果
[ 8 14 8]
[14]
[ 3 8 14 8 3]
a = [1, 2, 3, 4]
v = [1, 2]
print(np.correlate(a, v, mode0))
print(np.correlate(a, v, mode1))
print(np.correlate(a, v, mode2))
# 结果
[ 2 5 8 11]
[ 5 8 11]
[ 2 5 8 11 4]