VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-compute-cross-correlation-of-two-given-numpy-arrays/

⇱ How to compute cross-correlation of two given NumPy arrays? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to compute cross-correlation of two given NumPy arrays?

Last Updated : 8 Dec, 2020

In the Numpy program, we can compute cross-correlation of two given arrays with the help of correlate(). In this first parameter and second parameter pass the given arrays it will return the cross-correlation of two given arrays.

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.

Example 1:

In this example, we will create two NumPy arrays and the task is to compute cross-correlation using correlate().

Output:

[0 1 2]
[3 4 5]

Cross-correlation:
 [14]


Example 2:

Output:

[1 2]
[1 2]

Cross-correlation:
 [5]
Comment