Weighted element-wise between two arrays, numpy

46 views Asked by At

I want to perform

array_0 = np.array([ [1,2,3], [1,2,3], [1,2,3] ])
array_1 = np.array([ [1,2,3], [1,2,3], [1,2,3] ])
weights = np.array([ 1, 5 ])

result = array_0 * weights[0] + array_1 * weights[1]

Is there a numpy function that does just that?

Obviously, I could use numpy.average() with 1==sum(weights), and then multiply the result to compensate, but my question is: is there a function that does the sum-product without tricks?

Also, my question may be invalid: I assume that w1*A1+w2*A2+w3*A3+... results in as many for loops as there are operation, not just a single elementwise for loop.

There is a similar question, which does not work in my case:

element-wise weighted average

0

There are 0 answers