ExampleEdit & Run
#Use the math.exp function

#import the math module
import math

#Use the math.exp function

print(math.exp(5))
copy
Output:
148.4131591025766 [Finished in 0.010784063022583723s]

The math.exp() function calculates the value of e (the base of natural logarithms) raised to the power of a given number. This value is known the "exponential value" or "exponential function" of the input number. It is equal to the inverse of the natural logarithm (ln) of the number.

The math.exp() function takes one argument, the power to which e is to be raised, and returns the result as a floating-point number.

Syntax:
math.exp(x) 
copy

Where x is the exponent to which e is to be raised.

ExampleEdit & Run
import math

result = math.exp(2.0)
print(result)
copy
Output:
7.38905609893065 [Finished in 0.010765104088932276s]

Where is the Value of e^x commonly used?

This value is useful in a variety of  mathematical and scientific calculations:

Probability calculations

The exponential function is frequently used in probability and statistics. For instance, when working with exponential distributions, the exp() function is used to calculate the probability density function (PDF).

ExampleEdit & Run
import math

x = 2.5
mu = 1.0
sigma = 0.5

pdf = (1 / (sigma * math.sqrt(2 * math.pi))) * math.exp(-(x - mu) ** 2 / (2 * sigma ** 2))
print(pdf)
copy
Output:
0.008863696823876015 [Finished in 0.010655739810317755s]

Growth modeling:

The exponential function is often used to model growth patterns in various fields, such as finance, population studies, and biology.

ExampleEdit & Run
import math

initial_value = 100
growth_rate = 0.05
years = 3

final_value = initial_value * math.exp(growth_rate * years)
print(final_value)
copy
Output:
116.1834242728283 [Finished in 0.009812774136662483s]

In the above example, we calculate the final value after 3 years of exponential growth with an initial value of 100 and a growth rate of 0.05. The math.exp() function is used to calculate the growth factor.

Exponential smoothing

Exponential smoothing is a technique used to analyze and predict patterns in data, particularly in time series data. It helps to reduce noise and uncover underlying trends. In this case the math.exp function can be used to  calculate the exponential weights.

Machine learning and data analysis:

In machine learning and data analysis tasks, the exp() function can be employed in mathematical operations, such as normalizing data, calculating likelihoods in certain models, or transforming features to handle skewed distributions.