I have used numpy.where() so many times now, and I always wondered about the following statement in the docs:
x, y and condition need to be broadcastable to some shape.
I see why this is necessary for both x and y. We want to assemble the resulting array from the two, so they should be broadcastable to the same shape. However, I do not understand why this is so important for the condition as well. It is only the decision rule. Suppose I have the following three shapes:
condition = (100,)
x = (100, 5)
y = (100, 5)
result = np.where(condition, x, y)
This results in a ValueError, because the "operands could not be broadcast together". To my understanding, this expression should work just fine, because I compose my result of both x and y which are broadcastable.
Can you help me understand why it is so important for the condition to be broadcastable along with x and y?