Booleans in Python are implemented as ints and usually there is no difference in numpy
and other packages when changing 0
by False
and 1
by True
.
Why then these two computations differ?
>>> import numpy as np
>>> np.trapz([1,1])
1.0
>>> np.trapz([True, True])
0.5
The same thing happens with scipy.integrate
.
Found it. It seems to be a bug: https://github.com/numpy/numpy/issues/12858
As pointed in the issue, the key is that
>>> True + True
2
>>> np.True_ + np.True_
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With