Challenge - 5 Problems
Random Array Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
Output shape of np.random.rand() with multiple dimensions
What is the shape of the array produced by
np.random.rand(3, 4, 2)?NumPy
import numpy as np arr = np.random.rand(3, 4, 2) print(arr.shape)
Attempts:
2 left
💡 Hint
The arguments to np.random.rand() specify the size of each dimension in order.
✗ Incorrect
np.random.rand(3, 4, 2) creates a 3D array with shape (3, 4, 2). The first argument is the size of the first dimension, the second is the second dimension, and so on.
❓ data_output
intermediate1:30remaining
Range of values from np.random.rand()
What is the range of values you can expect from
np.random.rand(5)?NumPy
import numpy as np arr = np.random.rand(5) print(arr.min(), arr.max())
Attempts:
2 left
💡 Hint
np.random.rand() generates floats in a specific range starting at zero.
✗ Incorrect
np.random.rand() generates random floats in the half-open interval [0, 1), meaning 0 is included but 1 is excluded.
❓ visualization
advanced2:00remaining
Visualizing distribution of np.random.rand() values
Which option correctly plots a histogram showing the distribution of 1000 values generated by
np.random.rand(1000)?NumPy
import numpy as np import matplotlib.pyplot as plt values = np.random.rand(1000) plt.hist(values, bins=20) plt.show()
Attempts:
2 left
💡 Hint
np.random.rand() generates uniform random numbers between 0 and 1.
✗ Incorrect
Since np.random.rand() produces uniform random numbers, the histogram bars should be roughly even across the range from 0 to 1.
🧠 Conceptual
advanced1:30remaining
Effect of shape argument order in np.random.rand()
If you want to create a 2D array with 5 rows and 3 columns using
np.random.rand(), which call is correct?Attempts:
2 left
💡 Hint
The arguments to np.random.rand() are separate integers for each dimension.
✗ Incorrect
np.random.rand() takes each dimension as a separate argument, so np.random.rand(5, 3) creates an array with 5 rows and 3 columns.
🔧 Debug
expert2:00remaining
Identify the error in this np.random.rand() usage
What error will this code raise?
import numpy as np arr = np.random.rand([2, 3]) print(arr.shape)
NumPy
import numpy as np arr = np.random.rand([2, 3]) print(arr.shape)
Attempts:
2 left
💡 Hint
np.random.rand() expects separate integer arguments, not a list.
✗ Incorrect
Passing a list as a single argument causes a TypeError because np.random.rand() tries to interpret it as an integer dimension size.