Bird
0
0

You want to create a 2D array with 3 rows and 4 columns filled with random floats between 0 and 1, then multiply all values by 10 to scale them. Which code correctly does this?

hard📝 Application Q15 of 15
NumPy - Creating Arrays
You want to create a 2D array with 3 rows and 4 columns filled with random floats between 0 and 1, then multiply all values by 10 to scale them. Which code correctly does this?
Aarr = np.random.rand(12) * 10
Barr = np.random.rand(3, 4) * 10
Carr = np.random.rand(3) * 4 * 10
Darr = np.random.rand(3, 4) + 10
Step-by-Step Solution
Solution:
  1. Step 1: Create a 3x4 array of random floats

    Use np.random.rand(3, 4) to get a 2D array with 3 rows and 4 columns.
  2. Step 2: Scale all values by 10

    Multiply the entire array by 10 to scale values from [0,1) to [0,10).
  3. Final Answer:

    arr = np.random.rand(3, 4) * 10 -> Option B
  4. Quick Check:

    Shape and scaling done correctly [OK]
Quick Trick: Multiply after rand() to scale values, keep shape in arguments [OK]
Common Mistakes:
  • Adding 10 instead of multiplying
  • Using wrong shape arguments
  • Creating 1D array instead of 2D

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes