Ok, this is admittedly guesswork, but the only explanation I can think of for your np.where(lower_bounds>0, histo1,0).sum()
returning the full sum is
- you are on Python2
- lower_bounds is a list, not an array
on Python2:
[1, 2] > 0
True
meaning that your numpy line will broadcast its first argument and always pick from histo1, never from 0. Note that the alternative formulation that was suggested in the comments histo1[lower_bounds>0].sum()
will not work either (it will return histo1[1]
) in this situation.
The solution. Explicitly convert lower_bounds to an array
np.where(np.array(lower_bounds)>0, histo1, 0)
Btw. on Python3 you would get an exception
[1, 2] > 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '>' not supported between instances of 'list' and 'int'