I am trying to understand the mode "same" in the function np.correlate(). I saw the definition in some website, but I can't understand how it does the computation to get the final array.
How from this: np.correlate([2, 1], [1, 1], 'same') we get this: array([2, 3])
Can someone make a computation example?
The mode='same' just implies that you will have a result equal to the size of the largest input array. It is a subset of the full cross correlation (there is a mode='full' option as well). In your example, we have:
2 1
1 1
------
0+2+0 = 2
(dot product, zero fill where appropriate, then "slide")
2 1
1 1
-----
2+1 = 3
Hence the answer of [2,3].
The full cross correlation would continue sliding.
2 1
1 1
-------
0+1+0 = 1
So, the full cross correlation would be [2,3,1].
Note: These keywords are derived from the MATLAB implementations of these functions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With