Challenge - 5 Problems
Normal Distribution Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of numpy normal() with fixed seed
What is the output of this code snippet that generates 3 random numbers from a normal distribution with mean 0 and standard deviation 1?
NumPy
import numpy as np np.random.seed(0) samples = np.random.normal(0, 1, 3) print(samples)
Attempts:
2 left
💡 Hint
Remember to set the random seed before generating samples to get reproducible results.
✗ Incorrect
Setting np.random.seed(0) fixes the random number generator state. The first three samples from np.random.normal(0,1,3) with this seed are [1.76405235, 0.40015721, 0.97873798].
❓ data_output
intermediate1:30remaining
Shape of output array from normal()
What is the shape of the array produced by this code?
NumPy
import numpy as np result = np.random.normal(loc=5, scale=2, size=(4,3)) print(result.shape)
Attempts:
2 left
💡 Hint
The size parameter defines the shape of the output array.
✗ Incorrect
The size=(4,3) argument tells numpy to generate a 2D array with 4 rows and 3 columns, so the shape is (4, 3).
❓ visualization
advanced2:30remaining
Histogram of samples from normal distribution
Which option shows the correct histogram plot code for 1000 samples from a normal distribution with mean 0 and standard deviation 1?
NumPy
import numpy as np import matplotlib.pyplot as plt samples = np.random.normal(0, 1, 1000) # Fill in the code to plot histogram
Attempts:
2 left
💡 Hint
Histograms show frequency distribution of data values.
✗ Incorrect
Option D correctly uses plt.hist() to plot the frequency distribution of the 1000 samples with 30 bins, which is the standard way to visualize a normal distribution sample.
🧠 Conceptual
advanced1:30remaining
Effect of scale parameter in normal()
What happens to the spread of data when you increase the scale parameter in np.random.normal(loc=0, scale=scale_value, size=1000)?
Attempts:
2 left
💡 Hint
Scale is the standard deviation of the normal distribution.
✗ Incorrect
The scale parameter controls the standard deviation. Increasing it makes the data spread wider around the mean.
🔧 Debug
expert2:00remaining
Identify error in normal() usage
What error will this code raise and why?
import numpy as np
samples = np.random.normal(0, -1, 5)
print(samples)
NumPy
import numpy as np samples = np.random.normal(0, -1, 5) print(samples)
Attempts:
2 left
💡 Hint
Scale (standard deviation) must be positive.
✗ Incorrect
The scale parameter cannot be negative. Passing -1 causes numpy to raise a ValueError indicating scale must be non-negative.