Why am I getting different result using dot and for loop

At least that, in the loop approach, your p needs to be reinitialized to 0 at each round of your first loop.

1 Like

Tip: Your vectorized version doesn’t really need any for-loops at all.