Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
NumPy - Array Operations
What will be the output of this code?
import numpy as np
x = np.array([3, 6, 9])
y = np.array([2, 4, 8])
z = x - y
print(z)
A[3 2 1]
B[5 10 17]
C[6 10 17]
D[1 2 1]
Step-by-Step Solution
Solution:
  1. Step 1: Understand element-wise subtraction

    Each element in array x is subtracted by the corresponding element in y.
  2. Step 2: Perform subtraction

    3 - 2 = 1, 6 - 4 = 2, 9 - 8 = 1
  3. Final Answer:

    [1 2 1] -> Option D
  4. Quick Check:

    Check each subtraction matches output [OK]
Quick Trick: Subtract arrays element-wise using '-' operator [OK]
Common Mistakes:
  • Adding instead of subtracting arrays
  • Confusing element-wise with matrix subtraction
  • Mismatching array lengths

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes