首页 > 编程 > Python > 正文

Python使用scipy模块实现一维卷积运算示例

2019-11-25 11:45:59
字体:
来源:转载
供稿:网友

本文实例讲述了Python使用scipy模块实现一维卷积运算。分享给大家供大家参考,具体如下:

一 介绍

signal模块包含大量滤波函数、B样条插值算法等等。下面的代码演示了一维信号的卷积运算。

二 代码

import numpy as npimport scipy.signalx = 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 100010int 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;//卷积后数组长度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;}

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python数学运算技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程

希望本文所述对大家Python程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表