Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy bitwise operator priority?

What's the priority ranking of numpy bitwise operators & and | ?

if I do

a & b | c

what expression does it evaluate? a & (b | c) ? (a & b) | c ?

How about

a | b & c

I also assume NOT (~) has the highest priority?

like image 294
CuriousMind Avatar asked Sep 22 '26 04:09

CuriousMind


1 Answers

Here is a technique that you can use when your internet connection is down. It is applicable to many questions that you might have. The colloquial description of the technique is "Suck it and see".

>>> from itertools import product
>>> list(product(range(2), repeat=3))
[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)]
>>> all((a & b | c) == ((a & b) | c) for a, b, c in product(range(2), repeat=3))
True
>>> all((a & b | c) == (a & (b | c)) for a, b, c in product(range(2), repeat=3))
False
like image 74
John Machin Avatar answered Sep 25 '26 03:09

John Machin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!