How do I check if a sympy expression evaluates to nan?
I simply need to do something like this:
if is_nan( expression ):
#Do stuff
In sympy, you can check for equality with the sympy nan object:
>>> alpha = sympy.nan
>>> alpha == sympy.nan
True
In numpy, you cannot check for equality with the numpy nan object:
>>> alpha = numpy.nan
>>> alpha == numpy.nan
False
>>> numpy.isnan(alpha)
True
Hence there exists a numpy.isnan() method, and there does not exist a sympy.isnan() method.
Credit to Morgan Thrapp
In SymPy, ==
always checks structural equality (that is, if two expressions are exactly equal). This works even for nan, so there is no need for a separate isnan
function (strictly speaking, SymPy's nan isn't an IEEE 754 nan).
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