Suppose I have a 2x3 matrix A:
1 2 3
4 5 6
and a vector y of length 4:
0 1 2 1
as well as another 4x2 matrix B:
0 0
1 1
2 2
3 3
I want to update the columns of A multiple times by adding from rows of B.
And the index of columns of A to be updated is given by y.
Using for loops, this can be done as:
for i in np.arange(4):
A[:,y[i]] += B[i,:]
I had implemented this using ufunc.at as:
np.add.at(A.T,y,B)
However, the performance of ufunc.at is almost as bad as using for loops.
How can I get a different vectorized implementation?
Updating using A[:,y]+=B.T seems to update each column only once.