Check if Sympy Expression is Nan?

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).

Tags:

Python

Nan

Sympy