I am trying to mask some elements in an array such that a mathematical operation is not applied to these elements.
I ran this code
import numpy as np
inp = np.random.randn(5, 5)
c = np.random.randn(5,5)
mask = inp > 0
inp[mask] += c
print(inp)
but I got this error
ValueError: operands could not be broadcast together with shapes (25,) (5,5) (25,)
input[mask]to see if it looks like you expect?inputin your case would shadow the built-in input functioninp[mask] += c[mask]should work