How to generate normally distributed data with NumPy using Python

1 min

Generating data can be useful in many ways. It is often used when you want to

  1. Do a Monte-Carlo simulation (E.g. to test out whether a model is working or not)
  2. Create a statistical model that utilizes random noise. (E.g. random walk)
  3. Create synthetic data. (E.g. based on an existing distribution)
  4. etc...

We call those processes "Data Generative Processes" or DGA.

When data is generated according to what we observe in the real world.

Enough talking, let's code

The formula

The normal distribution formula

The code

Let's generate data using NumPy's normally distributed data generator numpy.random.normal().

To this function, we have to pass three arguments.

  1. The mean of our distribution: mu
  2. A standard deviation: std
  3. How many random numbers do we want: n
import numpy as np

# We set our three arguments
mu = 0
std = 1
n = 50

# We generate a list of n randomly distributed observation
randomly_generated_data = np.random.normal(mu, std, n)

Here you are! You now know how to generate normally distributed data with NumPy using Python.

More on statistics

If you liked what you read and want to know more about how to apply Statistics in Python and avoid a few headaches... check out the other articles I wrote by clicking just here:

Statistics - The Python You Need
We gathered the only Python essentials that you will probably ever need.