Bird
0
0

Given arrays:

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

Which code correctly computes the element-wise average of a and b?
Anp.mean([a, b])
B(a + b) / 2
Cnp.average(a, b)
Da + b / 2
Step-by-Step Solution
Solution:
  1. Step 1: Calculate element-wise sum

    a + b adds elements pairwise.
  2. Step 2: Divide sum by 2 element-wise

    Dividing by 2 computes average for each element.
  3. Final Answer:

    (a + b) / 2 -> Option B
  4. Quick Check:

    Element-wise average = (a + b) / 2 [OK]
Quick Trick: Add arrays then divide by 2 for element-wise average [OK]
Common Mistakes:
  • Using np.mean on list returns scalar
  • Misusing np.average
  • Wrong operator precedence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes