mystify
Banana Enthusiast
Divine
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
400 XP
In this tutorial you will learn:
Rayleigh Distribution
Rayleigh Distribution is a continuous probability distribution named after English Lord Rayleigh. This distribution is for non-negative random variables and it is essentially a chi square distribution with two degrees of freedom. Rayleigh distribution is used to model the wind speeds, wave heights and sound radiations. It also gives measure the life time of electrical components like capacitors, resistors, transistors etc.
Rayleigh Distribution in Python
The random module of python’s NumPy library provide an inbuilt function rayleigh() for implementation of Rayleigh Distribution. The rayleigh() function takes in two parameters, first parameter is the “size” of the array which we require as an output and it is the mandatory parameter. The second parameter “scale” is an optional parameter and it is the standard deviation which decides the flatness of distribution, if this parameter is not explicitly defined its value is taken as 1.0 by default.
Lets take an example, we will generate a 1D array(1,5) of Rayleigh distribution with scale 2.0. In this code we can see that we are importing the random module in the second line of the code and in the fourth line we are applying the Rayleigh distribution with output size parameter (1,5) and standard deviation “scale” 2.0.
Lets take another example, in this example we will generate a 2D array of Rayleigh distribution having size (2,5) with default standard deviation.
In this example we will generate a 3D array of Rayleigh distribution of the size(2,4,2) with standard deviation 1.5
Visualization of Rayleigh Distribution
In this example we will visualize the Rayleigh Distribution with default value of standard deviation using the displot function of seaborn library.
Book traversal links for Rayleigh Distributon in Python
Download
- What is Rayleigh Distribution?
- Rayleigh Distribution Implementation in python
- Visualization of Rayleigh Distribution
Rayleigh Distribution
Rayleigh Distribution is a continuous probability distribution named after English Lord Rayleigh. This distribution is for non-negative random variables and it is essentially a chi square distribution with two degrees of freedom. Rayleigh distribution is used to model the wind speeds, wave heights and sound radiations. It also gives measure the life time of electrical components like capacitors, resistors, transistors etc.
Rayleigh Distribution in Python
The random module of python’s NumPy library provide an inbuilt function rayleigh() for implementation of Rayleigh Distribution. The rayleigh() function takes in two parameters, first parameter is the “size” of the array which we require as an output and it is the mandatory parameter. The second parameter “scale” is an optional parameter and it is the standard deviation which decides the flatness of distribution, if this parameter is not explicitly defined its value is taken as 1.0 by default.
Lets take an example, we will generate a 1D array(1,5) of Rayleigh distribution with scale 2.0. In this code we can see that we are importing the random module in the second line of the code and in the fourth line we are applying the Rayleigh distribution with output size parameter (1,5) and standard deviation “scale” 2.0.
- #importing the random module
- from
numpy import
random
- #applying the Rayleigh function
- res_arr=
random
.rayleigh
(
size=
4
,
scale=
2.0
)
- #printing the results
- print
(
'1D array of size(1,5) having Rayleigh distribution with scale 2.0 :\n
'
)
- print
(
res_arr)
Lets take another example, in this example we will generate a 2D array of Rayleigh distribution having size (2,5) with default standard deviation.
- #importing the random module
- from
numpy import
random
- #here we are using Rayleigh function to generate Rayleigh distribution of size 2 x 5 with default scale value
- res_arr =
random
.rayleigh
(
size=
(
2
,
5
)
)
- print
(
'2D Rayleigh Distribution as output from rayleigh() function:\n
'
)
- #printing the result
- print
(
res_arr)
In this example we will generate a 3D array of Rayleigh distribution of the size(2,4,2) with standard deviation 1.5
- #importing the random module
- from
numpy import
random
- #here we are using Rayleigh function to generate Rayleigh distribution of size 2 x 4 x 2
- res =
random
.rayleigh
(
size=
(
2
,
4
,
2
)
,
scale=
1.5
)
- print
(
'3D Rayleigh Distribution as output from rayleigh() function:\n
'
)
- #printing the result
- print
(
res)
Visualization of Rayleigh Distribution
In this example we will visualize the Rayleigh Distribution with default value of standard deviation using the displot function of seaborn library.
- #importing all the required modules and packages
- from
numpy import
random
- import
matplotlib.pyplot
as
mpl
- import
seaborn as
sb
- #here we are using Rayleigh function to generate distributions of size 2000 with standard deviation 1
- sb.distplot
(
random
.rayleigh
(
size=
2000
)
,
hist=
False
,
label=
'Rayleigh Distribution'
)
- #plotting the graph
- mpl.show
(
)
Book traversal links for Rayleigh Distributon in Python
- ‹ Python Seaborn
- Up
- Rectangular Distribution in Python ›
Download
You must upgrade your account or reply in the thread to view hidden text.