C3_W1 Exercise 2

What is rong with my gaussian generator? I’m getting only 90% because of this

def inverse_cdf_gaussian(y, mu, sigma):
“”"
Calculates the inverse cumulative distribution function (CDF) of a Gaussian distribution.

Parameters:
- y (float or ndarray): The probability or array of probabilities.
- mu (float): The mean of the Gaussian distribution.
- sigma (float): The standard deviation of the Gaussian distribution.

Returns:
- x (float or ndarray): The corresponding value(s) from the Gaussian distribution that correspond to the given probability/ies.
"""
### START CODE HERE ###
x = sigma*np.sqrt(2)*erfinv(2*y - 1) + mu
### END CODE HERE ###

return x

def gaussian_generator(mu, sigma, num_samples):
### START CODE HERE ###

# Generate an array with num_samples elements that distribute uniformally between 0 and 1
u = np.random.uniform(0, 1, num_samples)

# Use the uniform-distributed sample to generate Gaussian-distributed data
# Hint: You need to sample from the inverse of the CDF of the distribution you are generating
array = inverse_cdf_gaussian(u, mu, sigma)
### END CODE HERE ###

return array

You may want to take a look at the line where you assign a value to u. I think there’s a function from exercise 1 that’s supposed to be called there instead.