python numpy np.convolve()函数(返回两个一维序列的离散线性卷积)
文章目录
- from numpy.core.numeric()
- 计算流程
from numpy.core.numeric()
def convolve(a, v, mode='full'):"""Returns the discrete, linear convolution of two one-dimensional sequences.返回两个一维序列的离散线性卷积。The convolution operator is often seen in signal processing, where itmodels the effect of a linear time-invariant system on a signal [1]_. Inprobability theory, the sum of two independent random variables isdistributed according to the convolution of their individualdistributions.卷积算子经常出现在信号处理中,它在信号[1] _上模拟线性时不变系统的效果。 在概率论中,两个独立随机变量之和是根据它们各自分布的卷积分布的。If `v` is longer than `a`, the arrays are swapped before computation.如果“ v”长于“ a”,则在计算之前交换数组。Parameters----------a : (N,) array_likeFirst one-dimensional input array.第一个一维输入数组。v : (M,) array_likeSecond one-dimensional input array.第二个一维输入数组。mode : {'full', 'valid', 'same'}, optional'full':By default, mode is 'full'. This returns the convolutionat each point of overlap, with an output shape of (N+M-1,). Atthe end-points of the convolution, the signals do not overlapcompletely, and boundary effects may be seen.默认情况下,模式为“完整”。 这将在每个重叠点返回卷积,输出形状为(N + M-1,)。 在卷积的端点,信号没有完全重叠,并且可以看到边界效应。'same':Mode 'same' returns output of length ``max(M, N)``. Boundaryeffects are still visible.模式'same'返回长度为``max(M,N)``的输出。 边界效果仍然可见。'valid':Mode 'valid' returns output of length``max(M, N) - min(M, N) + 1``. The convolution product is only givenfor points where the signals overlap completely. Values outsidethe signal boundary have no effect.模式'valid'返回长度为``max(M,N)-min(M,N)+ 1''的输出。 卷积仅针对信号完全重叠的点给出。 信号边界之外的值无效。Returns-------out : ndarrayDiscrete, linear convolution of `a` and `v`.a和v的离散线性卷积。See Also--------scipy.signal.fftconvolve : Convolve two arrays using the Fast FourierTransform.scipy.signal.fftconvolve:使用快速傅立叶变换对两个数组进行卷积。scipy.linalg.toeplitz : Used to construct the convolution operator.scipy.linalg.toeplitz:用于构造卷积运算符。polymul : Polynomial multiplication. Same output as convolve, but alsoaccepts poly1d objects as input.polymul:多项式乘法。 与卷积相同的输出,但也接受poly1d对象作为输入。Notes-----The discrete convolution operation is defined as.. math:: (a * v)[n] = \\sum_{m = -\\infty}^{\\infty} a[m] v[n - m]It can be shown that a convolution :math:`x(t) * y(t)` in time/spaceis equivalent to the multiplication :math:`X(f) Y(f)` in the Fourierdomain, after appropriate padding (padding is necessary to preventcircular convolution). Since multiplication is more efficient (faster)than convolution, the function `scipy.signal.fftconvolve` exploits theFFT to calculate the convolution of large data-sets.离散卷积运算定义为.. math ::(a * v)[n] = \\ sum_ {m =-\\ infty} ^ {\\ infty} a [m] v [n-m]可以证明,在适当的情况下,时间/空间中的卷积:x(t)* y(t)等价于傅立叶域中的乘积:math:`X(f)Y(f)`。 填充(必须填充以防止圆形卷积)。 由于乘法比卷积更有效(更快),因此函数“ scipy.signal.fftconvolve”利用FFT来计算大数据集的卷积。References----------.. [1] Wikipedia, "Convolution", http://en.wikipedia.org/wiki/Convolution.Examples--------Note how the convolution operator flips the second arraybefore "sliding" the two across one another:请注意,卷积运算符如何翻转第二个数组,然后才将它们“滑动”在一起:>>> np.convolve([1, 2, 3], [0, 1, 0.5])array([ 0. , 1. , 2.5, 4. , 1.5])Only return the middle values of the convolution.Contains boundary effects, where zeros are takeninto account:>>> np.convolve([1,2,3],[0,1,0.5], 'same')array([ 1. , 2.5, 4. ])The two arrays are of the same length, so thereis only one position where they completely overlap:>>> np.convolve([1,2,3],[0,1,0.5], 'valid')array([ 2.5])"""a, v = array(a, copy=False, ndmin=1), array(v, copy=False, ndmin=1)if (len(v) > len(a)):a, v = v, aif len(a) == 0:raise ValueError('a cannot be empty')if len(v) == 0:raise ValueError('v cannot be empty')mode = _mode_from_name(mode)return multiarray.correlate(a, v[::-1], mode)
咋算的,我一点都没看懂??
计算流程
示例:
数字输入的是离散信号,如下图。
已知x[0] = a,x[1]=b,x[2]=c
已知y[0]=i,y[1]=j,y[2]=k
下面演示x[n]*y[n]过程
第一步,x[n]乘以y[0]并平移到位置0:
第二步,x[n]乘以y[1]并平移到位置1:
第三步,x[n]乘以y[2]并平移到位置2:
最后,把上面三个图叠加,就得到了x[n] * y[n]:
参考文章:numpy中的convolve的理解
python numpy np.convolve()函数(返回两个一维序列的离散线性卷积)相关推荐
- python numpy np.argsort()(返回将对数组进行排序的索引)(不懂区别?)
from numpy\core\fromnumeric.py @array_function_dispatch(_argsort_dispatcher) def argsort(a, axis=-1, ...
- python numpy np.finfo()函数 eps
用法 finfo函数是根据括号中的类型来获得信息,获得符合这个类型的数型 例1: import numpy as np a=np.array([[1],[2],[-1],[0]]) b=np.maxi ...
- [转载] python numpy np.finfo()函数 eps
参考链接: Python中的numpy.log2 用法 finfo函数是根据括号中的类型来获得信息,获得符合这个类型的数型 例1: import numpy as np a=np.array([[1] ...
- python numpy np.fromstring()函数(从字符串文本中提取数字,返回一维数组)(爬虫提取数字挺好用的)
from numpy\core\multiarray.py def fromstring(string, dtype=None, count=-1, sep=''): # real signature ...
- [转载] python numpy np.exp()函数
参考链接: Python中的numpy.exp def exp(x, *args, **kwargs): # real signature unknown; NOTE: unreliably rest ...
- python numpy np.lexsort()(使用键序列执行间接稳定排序)(具体没太搞懂区别?)
from numpy\core_multiarray_umath.py @array_function_from_c_func_and_dispatcher(_multiarray_umath.lex ...
- Numpy:np.tile()函数
Numpy:np.tile函数 np.arange()函数 np.tile()函数 np.arange()函数 np.arange()函数返回的是一个有终点和起点的固定步长的排列,其中np.arang ...
- (python numpy) np.array.shape 中 (3,)、(3,1)、(1,3)的区别
(python numpy) np.array.shape 中 (3,).(3,1).(1,3)的区别 被人问到这个问题,就记录一下吧 1. (3,) (3,)是[x,y,z][x,y,z][x,y, ...
- python中使用zip函数基于两个列表数据list创建字典dict数据(Create a dictionary by passing the output of zip to dict)
python中使用zip函数基于两个列表数据list创建字典dict数据(Create a dictionary by passing the output of zip to dict) 目录
最新文章
- 如何看懂源代码--(分析源代码方法)(转)
- delete[] 出错
- 一些相当不错的php开源 AJAX聊天工具
- java mongo分组统计_探秘 Dubbo 的度量统计基础设施 - Dubbo Metrics
- java 链接mysql 产生500W数据模拟生成环境
- CoreOS裸机安装步骤(亲测)
- 网页版pdf转换方法
- lg相乘公式_lg的运算法则是什么
- 属于计算机网络硬件系统有哪些,下列不属于计算机硬件系统的是()
- 这六大方法,如何让 Transformer 轻松应对高难度长文本序列?
- IDR 关键帧 GOP
- python多窗口显示内容_如何在一个窗口中显示多个页面?
- 华硕ASUS手机平板官方刷机包raw格式解压修改工具
- uni-app APP端引入echart
- ffmpeg转换avi、mp4等视频格式为yuv格式
- 豆瓣《隐秘的角落》评论爬取
- 用html做七巧板的方法,第一天:html、css的初步学习和制作七巧板
- 转oracle数据库字符集AL32UTF8修改为ZHS16GBK即从超集到子集
- 2011税率改革 3500起征 个人所得税计算
- 如何快速查看MCC竞价账户下子账户的剩余预算金额?
热门文章
- java实现一个单例设计模式_Java正确实现一个单例设计模式的示例
- 【测试】RPA产品初体验
- 【文本描述增强】标准屏幕字段文本描述更改增强
- 释疑の采购订单的批量修改
- 企业是否真的需要BI?
- FM之NUMERIC_CHECK
- FM之DATE_CHECK_PLAUSIBILITY
- 在vs2005中使用Com连接SAP系统(二)
- 华为云FusionInsight+永洪BI共建政企用数之道,普惠千行百业
- “隐忍”多年的“水果大王”百果园要寻求资本协助了?