I had a 2D array (C) with 8000x64 elements, an 1D array (s) with 8000x1 elements and another 1D array (d) with 1x64 elements. Every row of index i, where s[i] is True, shall be added by vector d. This works quite well:
C[s == True] += d
Now I have added one dimension to C, s, and d and the logic above shall be applied to every element of the additional dimension.
The following code does what I want, but it's very slow.
for i in range(I):
C_this = C[:,:,i]
s_this = s[:,i]
d_this = d[:,i]
C_this[s_this == True] += d_this
C[:,:,i] = C_this
Is there a numpy way to do this without a for loop?
salready a boolean? If so, use it as a direct index.== Trueis not necessary.sis boolean. Thanks.