Bird
0
0

Which of the following correctly converts a 2D NumPy array arr into a 1D array using ravel()?

easy📝 Conceptual Q3 of 15
NumPy - Array Manipulation
Which of the following correctly converts a 2D NumPy array arr into a 1D array using ravel()?
Aflat_arr = np.flatten(arr)
Bflat_arr = np.ravel
Cflat_arr = arr.flatten
Dflat_arr = arr.ravel()
Step-by-Step Solution
Solution:
  1. Step 1: Identify the method call

    The ravel() method must be called on the array object with parentheses.
  2. Step 2: Check each option

    flat_arr = arr.ravel() correctly calls arr.ravel() which returns a flattened 1D array. flat_arr = np.ravel is just a reference to the function without calling it. flat_arr = arr.flatten misses parentheses, so it returns a method object, not the flattened array. flat_arr = np.flatten(arr) uses a non-existent np.flatten() function.
  3. Final Answer:

    flat_arr = arr.ravel() -> Option D
  4. Quick Check:

    Method call with parentheses returns flattened array [OK]
Quick Trick: Call ravel() with parentheses on the array [OK]
Common Mistakes:
  • Forgetting parentheses when calling ravel()
  • Using np.flatten() which does not exist
  • Assigning the method itself instead of its result

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes