Bird
0
0

What is the output of this code?

medium📝 Predict Output Q4 of 15
NumPy - Array Operations
What is the output of this code?
import numpy as np
x = np.array([2, 4, 6])
y = np.array([1, 3, 5])
z = x - y
print(z)
A[1 2 1]
B[1 3 5]
C[1 1 1]
D[3 7 11]
Step-by-Step Solution
Solution:
  1. Step 1: Perform element-wise subtraction

    Subtract each element of y from x: 2-1=1, 4-3=1, 6-5=1.
  2. Step 2: Confirm output array

    The result is an array with elements [1, 1, 1].
  3. Final Answer:

    [1 1 1] -> Option C
  4. Quick Check:

    Element-wise subtract result = [1 1 1] [OK]
Quick Trick: Subtract arrays element-wise with - operator [OK]
Common Mistakes:
  • Adding instead of subtracting
  • Mixing up array elements
  • Expecting scalar output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes