On 7 April 2016 at 14:08, Robert Kern <robert.kern@gmail.com> wrote:
This is a consequence of another unfortunate design by numpy. The reason for this is that numpy uses Python's bitwise operators to do element-wise logical operations.
This is not correct. & | ^ ~ are all genuine bitwise operations on numpy arrays.
i = np.arange(5) ~i array([-1, -2, -3, -4, -5])
What you are seeing with bool arrays is that bool arrays are *not* just uint8 arrays. Each element happens to take up a single 8-bit byte, but only one of those bits contributes to its value; the other 7 bits are mere padding. The bitwise & | ^ ~ operators all work on that single bit correctly. They do not operate on the padding bits as they are not part of the bool's value.
I stand corrected. -- Oscar