Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q13 of 15
NumPy - Fundamentals
What will be the output of this code?
import numpy as np
arr = np.array([1, 2, 3])
print(arr * 2)
A[2 4 6]
B[1 2 3 1 2 3]
C[3 4 5]
DError: unsupported operand
Step-by-Step Solution
Solution:
  1. Step 1: Understand array multiplication

    Multiplying a NumPy array by a number multiplies each element by that number.
  2. Step 2: Calculate element-wise multiplication

    Each element in [1, 2, 3] multiplied by 2 gives [2, 4, 6].
  3. Final Answer:

    [2 4 6] -> Option A
  4. Quick Check:

    Array * scalar = element-wise multiply [OK]
Quick Trick: Array * number multiplies each element [OK]
Common Mistakes:
  • Thinking it concatenates arrays
  • Expecting addition instead of multiplication
  • Confusing with Python list behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes