python自带的卷积

2023-01-31 05:01:26 python 卷积 自带

自带的卷积函数:

import matplotlib.pyplot as plt
import numpy as np
plt.plot([1,2,3,4])
plt.plot([1,1,3]) # 倒过来成为卷积核,然后在上述的数组中滑动,得到结果
end_1=np.convolve([1,2,3,4],[1,1,3],'full')
end_2=np.convolve([1,2,3,4],[1,1,3],'same')
end_3=np.convolve([1,2,3,4],[1,1,3],'valid')
plt.plot(end_1)
print(end_1)
print(end_2)
print(end_3)
plt.show()

’full‘ 结果 [ 1 3 8 13 13 12]
’same‘结果[ 3 8 13 13]
’valid‘结果[ 8 13]

相关文章