'How can I plot Gaussian pseudo-random noise for N = 2?

How would one plot the Gaussian pseudo-random noise when N = 2 from the given code below? I don't know how to incorporate N into the formula in the code.

I need to plot for N =1; N = 2; and N=10

Here is the requirement:

Create "size=1000" "N"-sample averages of uniformly distributed random variables. This requires that you generate N * size psuedo-random numbers.

import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
import math

# For reproducibility
np.random.seed(42)

y = np.random.uniform(size=1000)

# Plot the normalized histogram (i.e., the "sample" probability distribution)
facetGrid = sns.displot(y, stat="density", bins=25)

# Note: sns.displot returns a FacetGrid instance -- adding a title is a pain but it can be done
# See the API docs -- https://seaborn.pydata.org/generated/seaborn.FacetGrid.html
facetGrid.fig.suptitle("Gaussian pseudo-random noise")

# Plot a Gaussian PDF using sample mean and variance
sigma = np.std(y)
mu = np.mean(y)
x = np.linspace(np.min(y), np.max(y), 100)
a = 1 / math.sqrt(2 * math.pi) / sigma
x2 = -.5 * ((x - mu) / sigma)**2
y = a * np.exp(x2)
plt.plot(x, y, 'r-', lw=5, alpha=0.6, label='norm pdf');

plt.show()

Here is the plot from the above:

enter image description here



Solution 1:[1]

Could you do something like this instead?

# Plot a Gaussian PDF using sample mean and variance
mu = np.mean(y)
sigma = np.std(y)
x = np.linspace(mu - 3 * sigma, mu + 3 * sigma, 100)
plt.plot(x, np.exp(-(x - mu) ** 2 / (2 * sigma ** 2)) / (math.sqrt(2 * math.pi) * sigma), "r-")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PCDSandwichMan