Bird
0
0

Which of the following is the correct syntax to subtract array b from array a element-wise in numpy?

easy📝 Syntax Q3 of 15
NumPy - Array Operations
Which of the following is the correct syntax to subtract array b from array a element-wise in numpy?
Aa - b
Bnp.subtract(a, b)
CBoth A and C
Da.subtract(b)
Step-by-Step Solution
Solution:
  1. Step 1: Check subtraction syntax options

    Both a - b and np.subtract(a, b) perform element-wise subtraction.
  2. Step 2: Confirm a.subtract(b) is invalid

    Arrays do not have a subtract method, so this is incorrect.
  3. Final Answer:

    Both A and C -> Option C
  4. Quick Check:

    Element-wise subtract = a - b or np.subtract(a, b) [OK]
Quick Trick: Use - or np.subtract for element-wise subtraction [OK]
Common Mistakes:
  • Using a.subtract(b) which is invalid
  • Confusing subtraction with addition
  • Using wrong function names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes