Bird
0
0

Given two numpy arrays:

hard📝 Application Q8 of 15
NumPy - Array Operations
Given two numpy arrays:
a = np.array([[2, 4], [6, 8]])
b = np.array([[1, 3], [5, 7]])

Which of the following computes the element-wise difference and then divides each element by 2 in a single line?
A(a - b) / 2
Ba - (b / 2)
Ca / 2 - b
Da - b / 2
Step-by-Step Solution
Solution:
  1. Step 1: Compute element-wise difference

    Subtract b from a element-wise using a - b
  2. Step 2: Divide each element by 2

    Divide the resulting array by 2 using / 2
  3. Step 3: Combine in one line

    (a - b) / 2 performs both operations correctly
  4. Final Answer:

    (a - b) / 2 -> Option A
  5. Quick Check:

    Check order of operations and parentheses [OK]
Quick Trick: Use parentheses to control operation order in numpy [OK]
Common Mistakes:
  • Dividing only one array before subtraction
  • Ignoring parentheses leading to wrong order
  • Confusing element-wise division with matrix division

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes