Convolution卷积算法python以numpy,Matplotlib实现
2018-04-10 23:30
1171 查看
1:简述
Numpy拥有函数numpy.convolve(a, v, mode=’full’)[source]¶,通过该函数完成卷积算法并图形化(Matplotlib)实现。
2:卷积定理
原理:
设:f(x),g(x)是R1上的两个可积函数,作积分:
用处:
二个二维连续函数在空间域中的卷积可求其相应的二个傅立叶变换乘积的反变换而得。反之,在频域中的卷积可用的在空间域中乘积的傅立叶变换而得。
f(x,y) * h(x,y)<=>F(u,v)H(u,v)
f(x,y)h(x,y)<=>[F(u,v) * H(u,v)] (A * B 表示做A与B的卷积)
3:官方函数解读
numpy.convolve(a, v, mode=’full’)
(http://docs.scipy.org/doc/numpy/reference/generated/numpy.convolve.html#r17)
a,v是两个算子(array_like),mode有三种情况,’full‘ : 默认值,将计算每个点的卷积,即若a,v长度为n,m。最终输出图形x长度为(n+m-1),在边界处信号不完全重叠,即存在边界效应。‘same‘:返回长度为max(n,m),仍然有边界效应。‘valid‘:返回长度为max(n,m)-min(n,m)+1。其中只会显示两个信号重叠的部分,不会有边界效应。
类似功能函数:
scipy.signal.fftconvolve %使用快速傅里叶变换卷积函数。 scipy.linalg.toeplitz %可用于构造卷积运算符(Used to construct the convolution operator.)。 polymul %多项式乘法,可以同本函数获得相同的输出,但是还可以接受poly1d对象作为输入。
- 1234567
案例:
>>> np.convolve([1, 2, 3], [0, 1, 0.5]) array([ 0. , 1. , 2.5, 4. , 1.5]) >>> np.convolve([1,2,3],[0,1,0.5], 'same') array([ 1. , 2.5, 4. ]) >>> np.convolve([1,2,3],[0,1,0.5], 'valid') array([ 2.5])
- 1234567
4:编码尝试
%cmd -> ipython notebook %list和nparry都是单元数据,不能被直接plt。 %matplotlib inline import numpy as np import matplotlib.pyplot as plt plt.plot([1,2,3,4]) plt.plot([1,1,3]) end=np.convolve([1,2,3,4],[1,1,3],'full') plt.plot(end)
相关文章推荐
- Convolution卷积算法python以numpy,Matplotlib实现
- Python+matplotlib+numpy实现在不同平面的二维条形图
- winpython好用到哭了,自带numpy,scipy,matplotlib,scikit-learn
- Python Matplotlib的安装使用及Scipy,numpy,dateutil,pyparsing的安装
- Python2.7安装matplotlib、numpy
- Python2.7安装Numpy+Scipy+Matplotlib+Scikit-Learn
- Python搭建Numpy、SciPy、MatPlotLib环境(下载、安装、测试)
- Windows10+Python3.6下安装NumPy+SciPy+Matplotlib
- python 实现将 pandas 数据和 matplotlib 绘图嵌入 html 文件
- windows下python3.4安装Numpy和matplotlib
- win7下caffe的编译(包括caffe_python接口配置)以及python27下numpy、matplotlib、scipy等的安装
- 4000 Python:Ubuntu安装numpy,scipy,matplotlib
- Python 3.5.2 Numpy 和MatplotLib的安装
- Ubuntu-Python安装 scipy,numpy,matplotlib
- 如何在Linux系统Ubuntu版本下安装Python开发包NumPy、Matplotlib、SciPy
- Python配置第三方库Numpy和matplotlib的曲折之路
- Ubuntu-Python2.7安装 scipy,numpy,matplotlib (转)
- Python安装numpy,matplotlib,scikit_learn遇到的问题大汇总
- python使用安装numpy、scipy、matplotlib等工具包
- Python-PyCharm安装numpy和matplotlib