Bird
0
0

What will be printed by this code?

medium📝 Predict Output Q5 of 15
NumPy - Array Manipulation
What will be printed by this code?
import numpy as np
arr = np.array([[1, 2], [3, 4]])
r = arr.ravel()
r[0] = 10
print(arr[0, 0])
A1
BError
C10
D0
Step-by-Step Solution
Solution:
  1. Step 1: Understand ravel() returns a view if possible

    The ravel() method returns a view of the array if possible, so modifying r[0] changes arr[0, 0].
  2. Step 2: Check modified value

    After setting r[0] = 10, arr[0, 0] becomes 10.
  3. Final Answer:

    10 -> Option C
  4. Quick Check:

    ravel() returns view, changes affect original [OK]
Quick Trick: ravel() changes reflect in original array if view [OK]
Common Mistakes:
  • Assuming ravel() returns a copy
  • Expecting original array unchanged
  • Confusing flatten() and ravel() effects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes