Bird
0
0

What is the output of this code?

medium📝 Predict Output Q13 of 15
NumPy - Array Operations
What is the output of this code?
import numpy as np
x = np.array([1, 2, 3])
y = np.array([4, 5, 6])
print(x * y)
A[4 10 18]
B[5 7 9]
C[1 2 3 4 5 6]
DError: arrays must be same shape
Step-by-Step Solution
Solution:
  1. Step 1: Understand element-wise multiplication

    Multiplying two numpy arrays multiplies each element pair: 1*4=4, 2*5=10, 3*6=18.
  2. Step 2: Calculate output array

    The result is an array: [4, 10, 18].
  3. Final Answer:

    [4 10 18] -> Option A
  4. Quick Check:

    Element-wise multiply: [1*4, 2*5, 3*6] = [4 10 18] [OK]
Quick Trick: Multiply arrays element-wise: multiply each pair [OK]
Common Mistakes:
  • Adding instead of multiplying elements
  • Expecting concatenation of arrays
  • Thinking multiplication sums elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes