Should I use scipy.pi, numpy.pi, or math.pi? Should I use scipy.pi, numpy.pi, or math.pi? python python

Should I use scipy.pi, numpy.pi, or math.pi?


>>> import math>>> import numpy as np>>> import scipy>>> math.pi == np.pi == scipy.piTrue

So it doesn't matter, they are all the same value.

The only reason all three modules provide a pi value is so if you are using just one of the three modules, you can conveniently have access to pi without having to import another module. They're not providing different values for pi.


One thing to note is that not all libraries will use the same meaning for pi, of course, so it never hurts to know what you're using. For example, the symbolic math library Sympy's representation of pi is not the same as math and numpy:

import mathimport numpyimport scipyimport sympyprint(math.pi == numpy.pi)> Trueprint(math.pi == scipy.pi)> Trueprint(math.pi == sympy.pi)> False