How to convert sympy boolean to python normal boolean?

Viewed 33

sympy use it's own True/False type (i.e.true/false) as the result of judgement, which is not allowed to addition. For example,

(x>2).subs({x:2})+1

this script is not allowed. Is there any simple way to replace it?like,convert the type back to the normal python bool?

1 Answers

You can wrap it with bool() to get a Python boolean.

Or if you want something that is more symbolic, you can use Piecewise((1, x > 2), (0, True)) instead of x > 2.

Related