a = np.array([[20, 12, 6],
[12, 24, 18],
[ 0, 14, 30]])
b = np.array([1,0.5])
c = np.array([b ** i for i in range(0, 3)][::-1])
array([[1. , 0.25],
[1. , 0.5 ],
[1. , 1. ]])
using the second column in c, I want to get
[[20*0.25, 12*0.25, 6*0.25],
[12*0.5, 24*0.5, 18*0.5],
[ 0*1, 14*1, 30*1]
].sum(axis=0)
I want to do this for each column in c.
For 1-d array of c, I can do (a * c[:,None]).sum(axis=0). How can I vectorize the multiplication here without using loop?
You are looking for
np.eisumNote that you could use broadcasting although not as efficient as
eisum: