Bird
0
0

Which of the following is the correct way to add two NumPy arrays a and b element-wise using vectorization?

easy📝 Syntax Q12 of 15
SciPy - Integration with Scientific Ecosystem
Which of the following is the correct way to add two NumPy arrays a and b element-wise using vectorization?
Afor i in range(len(a)): c[i] = a[i] + b[i]
Bc = np.add(a, b, out=None, where=False)
Cc = a + b
Dc = a.append(b)
Step-by-Step Solution
Solution:
  1. Step 1: Review vectorized addition syntax

    NumPy supports element-wise addition directly with c = a + b.
  2. Step 2: Check other options

    for i in range(len(a)): c[i] = a[i] + b[i] uses a loop (not vectorized), np.add(a, b, out=None, where=False) has wrong parameters, c = a.append(b) is invalid for arrays.
  3. Final Answer:

    c = a + b -> Option C
  4. Quick Check:

    Use + for vectorized array addition [OK]
Quick Trick: Use c = a + b for fast element-wise addition [OK]
Common Mistakes:
  • Using loops instead of vectorized operators
  • Misusing np.add with wrong parameters
  • Trying to append arrays for addition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes