Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

numpy.correlate() function – Python

  • Last Updated : 11 Jun, 2020

numpy.correlate() function defines the cross-correlation of two 1-dimensional sequences. This function computes the correlation as generally defined in signal processing texts: 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.

Code #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)

Output :

[8.5]

 
Code #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)

Output :

[4.5 8.5 7. ]
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!