Defining a white noise process in Python Defining a white noise process in Python python python

Defining a white noise process in Python


You can achieve this through the numpy.random.normal function, which draws a given number of samples from a Gaussian distribution.

import numpyimport matplotlib.pyplot as pltmean = 0std = 1 num_samples = 1000samples = numpy.random.normal(mean, std, size=num_samples)plt.plot(samples)plt.show()

1000 random samples drawn from a Gaussian distribution of mean=0, std=1


Short answer is numpy.random.random(). Numpy site description

But since I find more and more answers to similar questions written as numpy.random.normal, I suspect a little description is needed. If I do understand Wikipedia (and a few lessons at the University) correctly, Gauss and White Noise are two separate things. White noise has Uniform distribution, not Normal (Gaussian).

import numpy.random as nprndimport matplotlib.pyplot as pltnum_samples = 10000num_bins = 200samples = numpy.random.random(size=num_samples)plt.hist(samples, num_bins)plt.show()

Image: Result

This is my first answer, so if you correct mistakes possibly made by me here, I'll gladly update it. Thanks =)


Create random samples with normal distribution (Gaussian) with numpy.random.normal:

import numpy as npimport seaborn as snsmu, sigma = 0, 1 # mean and standard deviations = np.random.normal(mu, sigma, size=1000) # 1000 samples with normal distribution# seaborn histogram with Kernel Density Estimationsns.distplot(s, bins=40, hist_kws={'edgecolor':'black'})

enter image description here