Bird
0
0

Which of the following is the correct syntax to add two numpy arrays a and b element-wise?

easy📝 Syntax Q12 of 15
NumPy - Array Operations
Which of the following is the correct syntax to add two numpy arrays a and b element-wise?
Anp.sum(a, b)
Ba.add(b)
Ca + b
Da.append(b)
Step-by-Step Solution
Solution:
  1. Step 1: Check numpy addition methods

    The + operator performs element-wise addition in numpy.
  2. Step 2: Evaluate options

    a.add(b) is invalid because numpy arrays do not have an add method. np.sum(a, b) computes sums, not element-wise addition. a.append(b) is a list method and errors on arrays.
  3. Final Answer:

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

    + operator adds arrays element-wise [OK]
Quick Trick: Use + for element-wise addition [OK]
Common Mistakes:
  • Using methods that don't exist on numpy arrays
  • Trying to add arrays with Python list methods
  • Confusing element-wise addition with matrix multiplication

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes