I have two arrays,
a = [3, 6, 8, 2, 5, 5]
b = [2, 7, 9]
and I need to create a new array c which takes the values and adds them like this: a[0+0]*b[0] + a[0+1]*b[1] + a[0+2]*b[2] = (3*2) + (6*7) + (9*8) = 6 + 42 + 72 which means c[0] = 120
I'm completely lost on how to do this anything to point me in the right direction would be awesome.
If c[k] = a[k+0]*b[0] + a[k+1]*b[1] + a[k+2]*b[2]
then
>>> c = [sum(i*j for i,j in zip(a[k:], b)) for k in range(4)]
>>> c
[120, 86, 75, 84]
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