Recall & Review
beginner
What does
np.random.rand() do?It creates an array of random numbers between 0 and 1, with the shape you specify.
Click to reveal answer
beginner
How do you create a 2x3 array of random numbers using
np.random.rand()?Use
np.random.rand(2, 3). This makes 2 rows and 3 columns of random numbers between 0 and 1.Click to reveal answer
beginner
What range of values does
np.random.rand() generate?It generates numbers from 0 (inclusive) up to 1 (exclusive). So, numbers are always >= 0 and < 1.
Click to reveal answer
intermediate
How is
np.random.rand() different from np.random.randn()?np.random.rand() generates uniform random numbers between 0 and 1, while np.random.randn() generates numbers from a normal (bell curve) distribution centered at 0.Click to reveal answer
beginner
Why might you use
np.random.rand() in data science?To create random samples or initialize arrays for simulations, testing algorithms, or creating random data for experiments.
Click to reveal answer
What does
np.random.rand(4, 2) produce?✗ Incorrect
np.random.rand(4, 2) creates a 4 rows by 2 columns array with random floats between 0 and 1.Which of these is true about numbers from
np.random.rand()?✗ Incorrect
Numbers from
np.random.rand() are >= 0 and < 1, so 1 is excluded.How to create a 1D array with 5 random numbers using
np.random.rand()?✗ Incorrect
np.random.rand(5) creates a 1D array with 5 random numbers.What is the difference between
np.random.rand() and np.random.randint()?✗ Incorrect
np.random.rand() generates floats between 0 and 1, while np.random.randint() generates random integers.If you want a 3D array of random numbers with shape (2, 3, 4), how do you call
np.random.rand()?✗ Incorrect
You pass each dimension as a separate argument:
np.random.rand(2, 3, 4).Explain how to create a 2D array of random numbers between 0 and 1 using
np.random.rand(). Include how to specify the shape.Think about rows and columns as arguments.
You got /4 concepts.
Describe the difference between
np.random.rand() and np.random.randn() and when you might use each.Consider the shape of the number distribution.
You got /4 concepts.