2019-09-05 15:24:20 4801瀏覽
今天千鋒扣丁學(xué)堂Python培訓(xùn)老師給大家分享一篇關(guān)于Python使用scipy模塊實現(xiàn)一維卷積運算示例詳解,結(jié)合實例形式分析了scipy模塊的功能及使用scipy模塊進行一維卷積運算的相關(guān)操作技巧,下面我們一起來看一下吧。
import numpy as np import scipy.signal x = np.array([1,2,3]) h = np.array([4,5,6]) print(scipy.signal.convolve(x, h))#一維卷積運算
[ 4 13 28 27 18]
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<map> #include<algorithm> usingnamespace std; #define INF 0xfffffff #define maxn 100010 int main() { int m=5,n=5; int a[5]={0,1,0,2,1},b[5]={0,1,0,2,1}; int i,j; int k=m+n-1;//卷積后數(shù)組長度 int c[k]; memset(c,0,sizeof(c));//注意一定要清零 /**卷積計算**/ for(i=0; i<k; i++) { for(j=max(0,i+1-n); j<=min(i,m-1); j++) c[i]+=a[j]*b[i-j]; cout<<c[i]<<" "; } /****/ cout<<endl; }
【關(guān)注微信公眾號獲取更多學(xué)習(xí)資料】 【掃碼進入Python全棧開發(fā)免費公開課】
查看更多關(guān)于"Python開發(fā)資訊"的相關(guān)文章>