Python numpy.correlate()函数
numpy.correlate()函数定义了两个一维序列的交叉相关。这个函数计算的是信号处理文本中通常定义的相关性:c_{av}[k] = sum_n a[n+k] * conj(v[n])
语法: numpy.correlate(a, v, mode = ‘valid’)
参数 :
a, v : [array_like] 输入序列。
mode : [{‘valid’, ‘same’, ‘full’}, optional] 请参考convolve文档串。默认为’有效’。
返回: [ndarray] a和v的离散交叉相关。
代码#1:
# Python program explaining
# numpy.correlate() function
# importing numpy as geek
import numpy as geek
a = [2, 5, 7]
v = [0, 1, 0.5]
gfg = geek.correlate(a, v)
print (gfg)
输出 :
[8.5]
代码#2:
# Python program explaining
# numpy.correlate() function
# importing numpy as geek
import numpy as geek
a = [2, 5, 7]
v = [0, 1, 0.5]
gfg = geek.correlate(a, v, "same")
print (gfg)
输出 :
[4.5 8.5 7. ]