I\'m new to NumPy, and I\'ve encountered a problem with running some conditional statements on numpy arrays. Let\'s say I have 3 numpy arrays that look like this:
a:
The problem is that you mask the receiving part, but do not mask the sender part. As a result:
c[(a > 3) & (b > 8)]+=b*2
# ^ 1x1 matrix ^3x4 matrix
The dimensions are not the same. Given you want to perform element-wise addition (based on your example), you can simply add the slicing to the right part as well:
c[(a > 3) & (b > 8)]+=b[(a > 3) & (b > 8)]*2
or make it more efficient:
mask = (a > 3) & (b > 8)
c[mask] += b[mask]*2