Bird
0
0

What does the function np.random.rand(3, 2) do in NumPy?

easy📝 Conceptual Q11 of 15
NumPy - Creating Arrays
What does the function np.random.rand(3, 2) do in NumPy?
ACreates a 3x2 array with random floats between 0 and 1
BCreates a 3x2 array filled with zeros
CCreates a 3x2 array with random integers
DCreates a 3x2 array filled with ones
Step-by-Step Solution
Solution:
  1. Step 1: Understand np.random.rand() function

    This function generates random floats between 0 and 1.
  2. Step 2: Analyze the shape arguments (3, 2)

    The arguments specify the shape of the output array as 3 rows and 2 columns.
  3. Final Answer:

    Creates a 3x2 array with random floats between 0 and 1 -> Option A
  4. Quick Check:

    np.random.rand(3, 2) = 3x2 random floats [OK]
Quick Trick: Remember rand() outputs floats in [0,1) with given shape [OK]
Common Mistakes:
  • Thinking it creates integers instead of floats
  • Confusing shape arguments with array values
  • Assuming it creates zeros or ones

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes