In the following code:
import numpy as np
a = np.array([1,3,5,7,9,11,13,15,17,19])
b = np.array([2,4,6,8,10,12,14,16,18,20])
c=0
for n in range(4,6):
c+= a[9-n]*b[n]
print(c)
You can easily calculate c using a for loop. If I do the following instead of the for loop:
d =0
d+= np.dot(a[5:3],b[4:6])
print(d)
I get the error message:
shapes (0,) and (2,) not aligned: 0 (dim 0) != 2 (dim 0)
How do you alter the code to correct this?