I'm using the numexpr module for python. I'm trying to run the next code snippet:
import numexpr as ne
def main():
result = ne.evaluate('where((1 > 9) & (where(1 > 9, 9, 1) == 0), 2, 3)')
print(f'Result: {result}')
if __name__ == "__main__":
main()
But numexpr
throws the following error:
TypeError: unsupported operand type(s) for &: 'bool' and 'ConstantNode'
However, if I extract the conflicting section in a separate expression, it works.
def main():
intermediate_result = ne.evaluate('where(1 > 9, 9, 1) == 0')
result = ne.evaluate(f'where((1 > 9) & {intermediate_result}, 2, 3)')
print(f'Result: {result}')
But the idea is to have a single expression. Does anyone know how I could rewrite this formula to make it work?
Thanks in advance.
&
is the bitwise and
operator. Why not just use and
?