pythonnumpynatural-logarithm

'e' the base of natural logarithm in python


name 'e' is not defined I ma getting this error in my python code. I have already imported the math and the numpy modules. What more do I need?


Solution

  • Use

    import math
    
    math.e
    

    Similar, for example:

    import math
    
    math.pi
    

    This way, it is clear which e (or pi) or meant, instead of a random letter e somewhere in your code.

    If you are using NumPy instead, you could do as follows:

    import numpy as np
    
    np.e
    

    (the NumPy import is generally abbreviated to np).

    Both e's are the same.