Bird
0
0

Which of the following is the correct way to add two numpy arrays a and b using vectorized operations?

easy📝 Syntax Q12 of 15
NumPy - Array Operations
Which of the following is the correct way to add two numpy arrays a and b using vectorized operations?
Ac = a + b
Bc = np.add(a, b)
Cc = [a[i] + b[i] for i in range(len(a))]
DBoth A and B
Step-by-Step Solution
Solution:
  1. Step 1: Identify vectorized addition methods

    Both a + b and np.add(a, b) perform element-wise addition efficiently.
  2. Step 2: Compare with loop method

    The list comprehension adds elements but is not vectorized and slower.
  3. Final Answer:

    Both A and B -> Option D
  4. Quick Check:

    Vectorized addition = a + b or np.add(a, b) [OK]
Quick Trick: Use + or np.add for vectorized addition [OK]
Common Mistakes:
  • Choosing list comprehension as vectorized
  • Thinking only np.add works
  • Using loops unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes