numpy.correlate()函数– Python
numpy.correlate()
函数定义两个一维序列的互相关。此函数计算信号处理文本中通常定义的相关性:c_{av}[k] = sum_n a[n+k] * conj(v[n])
Syntax : numpy.correlate(a, v, mode = ‘valid’)
Parameters :
a, v : [array_like] Input sequences.
mode : [{‘valid’, ‘same’, ‘full’}, optional] Refer to the convolve docstring. Default is ‘valid’.
Return : [ndarray] Discrete cross-correlation of a and 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. ]