# Exponential Distribution in Python

## In this tutorial you will learn:

• What is Exponential Distribution?
• Exponential Distribution Implementation in python
• Visualization of Exponential Distribution

## Exponential Distribution

Exponential Distribution is most widely used continuous distribution. The exponential distribution is concerned with amount of time until a specific event has occurred. As an example, the time elapsed between two pandemics or the time spent after last engine oil change of a vehicle can be modeled using exponential distribution. It has fewer larger values and more number of smaller values.

## Exponential Distribution in Python

Exponential distribution in python is implemented using an inbuilt function exponential() which is included in the random module of NumPy library. The exponential() function takes in two parameters. First parameter “size” is the mandatory parameter and it is size of the output array which could be 1D, 2D, 3D or n-dimensional (depending on the programmer’s requirements). The second parameter is inverse of rate defined by “scale”, it is an optional parameter and if it is not explicitly defined, its value is taken as 1.0.
Lets take an example, we will generate a 1D array(1,5) of exponential distribution with scale 2.5. In the second line of code we are importing random module from NumPy library and in fourth line we are calling the exponential function and passing it the value of scale.

`#importing the random modulefrom numpy import random#applying the exponential functionres_arr= random. exponential(scale = 2.5, size=5)#printing the resultsprint('1D array of size(1,5) having exponential distribution with scale 2.5:\n')print(res_arr)`

In this example we will generate a 2D array of exponential distribution having size (6,2) with default scale value.
`#importing the random modulefrom numpy import random#here we are using exponential function to generate exponential distribution of size 6 x 2 with default scale valueres_arr = random.exponential(size=(6,2))print('2D Exponential Distribution as output from exponential() function:\n')#printing the resultprint(res_arr)`

Lets take another example, in this example we will generate a 3D array of exponential distribution of the size(3,3,5) with scale 0.8
`#importing the random modulefrom numpy import random#here we are using exponential function to generate exponential distribution of size 3 x 3 x 5res = random.exponential(size=(3,3,5), scale=0.8)print('3D Exponential Distribution as output from exponential() function:\n')#printing the resultprint(res)`

## Visualization of Exponential Distribution

In this example we will visualize the Exponential Distribution with scale of 1.5.

`#importing all the required modules and packagesfrom numpy import randomimport matplotlib.pyplot as mplimport seaborn as sb#here we are using exponential function to generate distributions of size 1000 with scale 1.5sb.distplot(random.exponential(size=1000,scale=1.5), hist=False, label='Exp Distr')#plotting the graphmpl.show()`

### Tags

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.