Challenge - 5 Problems
Random Sampling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
Output of sampling from a normal distribution
What is the shape of the array produced by this code?
NumPy
import numpy as np sample = np.random.normal(loc=0, scale=1, size=(5, 3)) print(sample.shape)
Attempts:
2 left
💡 Hint
The size parameter defines the shape of the output array.
✗ Incorrect
The size=(5,3) argument creates a 2D array with 5 rows and 3 columns.
❓ data_output
intermediate1:30remaining
Mean of samples from uniform distribution
What is the approximate mean of the samples generated by this code?
NumPy
import numpy as np samples = np.random.uniform(low=10, high=20, size=10000) print(round(samples.mean(), 1))
Attempts:
2 left
💡 Hint
The mean of a uniform distribution is the midpoint between low and high.
✗ Incorrect
The mean of uniform(10, 20) is (10 + 20) / 2 = 15.
❓ visualization
advanced2:00remaining
Histogram shape of binomial samples
Which histogram shape best describes the samples from this binomial distribution?
NumPy
import numpy as np import matplotlib.pyplot as plt samples = np.random.binomial(n=10, p=0.5, size=1000) plt.hist(samples, bins=range(12), edgecolor='black') plt.show()
Attempts:
2 left
💡 Hint
Binomial with p=0.5 tends to be symmetric around n*p.
✗ Incorrect
The binomial distribution with n=10 and p=0.5 is symmetric and peaks near 5.
🧠 Conceptual
advanced1:30remaining
Effect of sample size on sample mean variance
If you increase the sample size from 10 to 1000 when sampling from a normal distribution, what happens to the variance of the sample mean?
Attempts:
2 left
💡 Hint
Think about how averaging many values affects variability.
✗ Incorrect
The variance of the sample mean decreases as sample size increases, making the mean more stable.
🔧 Debug
expert1:30remaining
Identify the error in random sampling code
What error does this code raise when run?
NumPy
import numpy as np samples = np.random.normal(loc=0, scale=1, size=-5) print(samples)
Attempts:
2 left
💡 Hint
Check the size parameter for validity.
✗ Incorrect
Negative size is invalid and raises a ValueError in numpy random functions.