# Random Rayleigh Distribution In NumPy

In this article, we will explore NumPy random rayleigh distribution, and demonstrate how to produce random numbers from this distribution through the numpy module.

## What is Rayleigh Distribution?

The Rayleigh distribution is a continuous probability distribution used to model the magnitude of the vector sum of independent Gaussian random variables.

The PDF of the Rayleigh distribution is given by:

`f(x; σ) = x/σ^2 * e^(-x^2/(2*σ^2))`

where x is the random variable, σ is the scale parameter, and e is the base of the natural logarithm.

The mean and variance of the Rayleigh distribution are given by:

```mean = σ*sqrt(π/2)
variance = (4-π)/2 * σ^2```

## Numpy Random Rayleigh Distribution

The numpy random rayleigh function is used to generate random numbers from a Rayleigh distribution.

According to Numpy random Rayleigh, rayleigh distributions are applied to signal analysis.

### Syntax

`numpy.random.rayleigh(scale=1.0, size=None)`

There are two parameters associated with it:

 Parameters Overview scale (standard deviation) determines how smooth the distribution will be (by default, 1.0). size Indicates the array’s shape.

Take a random sample of 4.5 with a size of 1 by 5 for rayleigh distribution:

#### Example:

from numpy import random mrx = random.rayleigh(scale=4.5, size=(1, 5)) print(mrx)

Create a sample for the rayleigh distribution with scale one and size two and one:

#### Example:

from numpy import random mrx = random.rayleigh(scale=1, size=(2, 1)) print(mrx)

## Visualization

Represent Rayleigh Distribution as follows:

#### Example:

from numpy import random import matplotlib.pyplot as pt import seaborn as sbn sbn.distplot(random.rayleigh(size=100), hist=False) pt.show()

Display Rayleigh Distribution also with histogram:

#### Example:

from numpy import random import matplotlib.pyplot as pt import seaborn as sbn sbn.distplot(random.rayleigh(size=3000), hist=True) pt.show()

Similarity Between Rayleigh and Chi Square Distribution

It should be noted that rayleigh and chi square distributions are equivalent when the standard deviation is equal to one and 2 degrees of freedom.

Numpy random rayleigh is useful in many cases, Some of them are included below:

### Wireless Communications

The Rayleigh distribution is used in wireless communications to model the magnitude of the received signal.

It can be used to generate random channel gains for simulations.

### Engineering

The Rayleigh distribution is used in engineering to model the strength of materials.

It can be used to generate random material strengths for simulations.

### Physics

The Rayleigh distribution is used in physics to model the magnitude of the displacement of a particle from its equilibrium position due to random forces.

Numpy random rayleigh can be used to generate random displacements for simulations.

+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0