What is numpy.random.normal and how to use it

Introduction

In this blog, we would discuss What is numpy.random.normal and how to use it. The normal distribution is a type of probability distribution that is symmetrical around the mean. This means that the probability of a value being greater than or less than the mean is the same. The normal distribution is also known as the bell curve because of its shape. Values that are more than one standard deviation from the mean are considered to be abnormal. This is because they are less likely to occur. The standard deviation is a measure of how spread out the values are. The normal distribution is important because it is used to model many real-world phenomena.

 

 

For example, the heights of people are normally distributed. This means that the vast majority of people are of average height with only a few being very tall or very short. The normal distribution is also used in statistics. Many statistical tests assume that the data is normally distributed. This means that the results of the tests are only accurate if the data is actually normally distributed. 

 

 

 

What is numpy.random.normal

 

What is Numpy?

In the world of research and engineering, NumPy is a widely used open-source basic Python module. It stands for Numerical Python, which was founded by data scientist Travis Oliphant in 2005. This package was created using a combination of Python and C++ programming. Pandas, SciPy, Matplotlib, scikit-learn, and scikit-image are just a few of the Python data science libraries that use the Numpy module.

 

Multidimensional arrays known as “ndarray objects” are provided by Numpy. It features a wide range of functions for mathematical operations, statistical operations, logical operations, fundamental linear algebra, random simulation, matrices, and much more.

 

Due to its distinctive shape, the probability density function of the normal distribution, which was independently discovered by Gauss and Laplace 200 years after De Moivre, is frequently referred to as the bell curve.

 

The inbuilt function would be of form numpy.random.normal(loc=0.0scale=1.0size=None) where the parameters are :

 

 

Loc: array-like of floats or floats. Average (the distribution’s “center”)

 

 

Scale: array-like of floats or floats

Standard deviation, also known as the distribution’s “width” or “spread.” It must not be negative,

 

 

Size: optional, int, or tuple of ints

output form When the shape is (m, n, k), for example, m * n * k samples are drawn. If loc and scale are both scalars and size is None (the default), only one value will be produced. If not, samples are taken using np.broadcast(loc, scale).size.

 

 

Returns: scalar or ndarray

drawn samples from the normal distribution using parameters.

 

 

 

How to use numpy.random.normal?

 

import numpy as np
import matplotlib.pyplot as plot
   

mean = 0 
std = 0.1
array = np.random.normal(0, 0.1, 1000)
print("1D Array filled with random values "
      "as per gaussian distribution : \n", array);

 

Visualization

 

count, bins, ignored = plot.hist(array, 30,density=True)
plot.plot(bins, 1/(std * np.sqrt(2 * np.pi)) *
          np.exp( - (bins - mean)**2 / (2 * std**2) ),
          linewidth=2, color='r')
plot.show()

 

 

 

 

Also, read what is Naive Bayes and its works.

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *