Is it faster to multiply all values and then use np.sum() than to use a for loop?

If I need to iterate over all values and multiply them with a constant, and then add them to another variable, is it faster to multiply all values doing something like: v1 * 0.2 and then use
np.sum() and add it to another variable? or is it the same to iterate over all vector elements with a for loop and inside the for loop do the multiplication and summation?

let me know if you need me to reformulate my question. :slight_smile:

1 Like

Hey @Rickard,
What can be a better way to show this via a simple experiment! Check out the version 10 of this kernel, and you will get to know the answer by yourself. Let me know if this helps.


1 Like

thank you for your answer, I’ll check it out! :slight_smile: