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
arr = np.array([2, 4, 6])
result = arr * np.array([3, 2, 1])
print(result)
A[6 4 1]
B[5 6 7]
C[6 8 6]
D[2 4 6]
Step-by-Step Solution
Solution:
  1. Step 1: Understand element-wise multiplication

    Multiplying two numpy arrays multiplies elements at corresponding indices.
  2. Step 2: Calculate manually

    2*3=6, 4*2=8, 6*1=6, so result is [6, 8, 6].
  3. Final Answer:

    [6 8 6] -> Option C
  4. Quick Check:

    Multiply elements pairwise [OK]
Quick Trick: Element-wise multiplication multiplies corresponding elements [OK]
Common Mistakes:
  • Adding instead of multiplying
  • Confusing element-wise with dot product
  • Ignoring array shapes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes