Challenge - 5 Problems
Random Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
Output of generating normal random variables
What is the output of this code snippet that generates 3 samples from a normal distribution with mean 0 and standard deviation 1 using scipy.stats?
SciPy
from scipy.stats import norm samples = norm.rvs(loc=0, scale=1, size=3) samples_rounded = [round(x, 2) for x in samples] samples_rounded
Attempts:
2 left
💡 Hint
The output is random but will be three float numbers around zero.
✗ Incorrect
The norm.rvs function generates random samples from a normal distribution. Since the mean is 0 and std dev is 1, the values will be floats near zero but random each time.
❓ data_output
intermediate1:00remaining
Shape of generated random variable array
What is the shape of the array generated by this code that samples from a uniform distribution?
SciPy
from scipy.stats import uniform samples = uniform.rvs(loc=0, scale=10, size=(4, 2)) samples.shape
Attempts:
2 left
💡 Hint
The size parameter defines the shape of the output array.
✗ Incorrect
The size=(4, 2) argument tells scipy to generate a 2D array with 4 rows and 2 columns.
🔧 Debug
advanced1:30remaining
Identify the error in random variable generation code
What error does this code raise when trying to generate samples from a binomial distribution?
SciPy
from scipy.stats import binom samples = binom.rvs(n=10, p=0.5, size='5')
Attempts:
2 left
💡 Hint
Check the type of the size argument.
✗ Incorrect
The size parameter must be an integer or tuple of integers, not a string. Passing '5' causes a TypeError.
🚀 Application
advanced2:00remaining
Generating and summarizing Poisson random variables
You generate 1000 samples from a Poisson distribution with lambda=3. Which option correctly describes the expected mean and variance of the samples?
SciPy
from scipy.stats import poisson samples = poisson.rvs(mu=3, size=1000) mean_val = samples.mean() var_val = samples.var()
Attempts:
2 left
💡 Hint
For Poisson distribution, mean equals variance.
✗ Incorrect
Poisson distribution has mean and variance equal to lambda (mu). So both mean and variance should be near 3.
🧠 Conceptual
expert1:30remaining
Effect of random seed on reproducibility
Which statement about setting a random seed before generating random variables with scipy.stats is correct?
Attempts:
2 left
💡 Hint
Think about reproducibility in experiments.
✗ Incorrect
Setting a random seed initializes the random number generator to a fixed state, so the same sequence of random numbers is produced each run.