r/pythonhelp • u/andron2000 • May 25 '21
Numpy - multiply elements of array by another array
Greetings,
I am stuck on trying to do something efficiently using Numpy (instead of for loops which are slower). I have an array of N elements, a = [a0,a1,...aN], where N is determined at run-time. I have another array b = [b0,b1,b2], which always has three elements. What I want is to multiply each element of array a by the array b (using Numpy utils, not loops), i.e. ans = [ a0 * b, a1 * b, ... aN * b ] = [ a0 *[b0,b1,b2], ... , aN * [b0,b1,b2]]. I am trying to find a rather straightforward and efficient way to do this, but I am having trouble, any help would be appreciative.
2
Upvotes