Challenge - 5 Problems
Uniform Random Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of numpy.random.random() shape
What is the shape of the array produced by
numpy.random.random((3, 4))?NumPy
import numpy as np arr = np.random.random((3, 4)) print(arr.shape)
Attempts:
2 left
💡 Hint
The argument to random() defines the shape of the output array.
✗ Incorrect
The function numpy.random.random() takes a shape tuple and returns an array of that shape filled with random floats between 0 and 1.
❓ data_output
intermediate2:00remaining
Range of values from numpy.random.random()
What is the range of values produced by
numpy.random.random(5)?NumPy
import numpy as np arr = np.random.random(5) print(arr)
Attempts:
2 left
💡 Hint
random() generates floats in the half-open interval [0.0, 1.0).
✗ Incorrect
numpy.random.random() generates floats from 0 (inclusive) up to but not including 1.
❓ visualization
advanced3:00remaining
Histogram of uniform random numbers
Which option shows the correct histogram plot code for 1000 samples from
numpy.random.random()?NumPy
import numpy as np import matplotlib.pyplot as plt samples = np.random.random(1000)
Attempts:
2 left
💡 Hint
Histograms show frequency distribution of values.
✗ Incorrect
Using plt.hist with bins and range shows the distribution of uniform random samples between 0 and 1.
🧠 Conceptual
advanced2:00remaining
Effect of seed on numpy.random.random()
What happens if you set the seed using
np.random.seed(42) before calling np.random.random(3) twice?Attempts:
2 left
💡 Hint
Seed fixes the random number generator state.
✗ Incorrect
Setting the seed makes the random numbers reproducible, so repeated calls produce the same output.
🔧 Debug
expert2:00remaining
Identify error in numpy.random.random() usage
What error does this code raise?
import numpy as np arr = np.random.random(3,4) print(arr)
Attempts:
2 left
💡 Hint
random() expects a single argument for shape, which should be a tuple.
✗ Incorrect
random() expects one argument for shape, passing two separate arguments causes TypeError.