-1

thanks to this link enter link description here, I've got a sense about numpy.correlate function.

[3 4]
[1 1 5 5]
= 3 * 1 + 4 * 1 = 7
  [3 4]
[1 1 5 5]
= 3 * 1 + 4 * 5 = 23
    [3 4]
[1 1 5 5]
= 3 * 5 + 4 * 5 = 35

my question is, how dose numpy.convolve do its job, which gives this result?

>>>np.convolve(W,X,'valid')
array([ 7, 19, 35])

how does numpy get the value 19 in the middle?

thanks in advance!

1 Answers1

2

Per your link:

The convolution of two signals is defined as the integral of the first signal, reversed, sweeping over ("convolved onto") the second signal and multiplied (with the scalar product) at each position of overlapping vectors.

You missed the bolded part. So what happens is actually this:

np.convolve([3, 4], [1, 1, 5, 5], 'valid')

4 * 1 + 3 * 1 = 7
4 * 1 + 3 * 5 = 19
4 * 5 + 3 * 5 = 35
Amadan
  • 191,408
  • 23
  • 240
  • 301
  • I like this explanation. how can it be re-worded in the case of multivariate (more than 2) signals/distributions? – develarist Dec 04 '20 at 12:35