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
list1 = [1, 2, 3]
arr1 = np.array(list1)
print(arr1 * 2)
AError: unsupported operand
B[1, 2, 3, 1, 2, 3]
C[[1, 2, 3], [1, 2, 3]]
D[2 4 6]
Step-by-Step Solution
Solution:
  1. Step 1: Convert list to NumPy array

    The list [1, 2, 3] becomes a NumPy array arr1.
  2. Step 2: Multiply array by 2

    NumPy multiplies each element by 2, resulting in [2 4 6].
  3. Final Answer:

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

    NumPy multiplies element-wise [OK]
Quick Trick: NumPy * number multiplies each element [OK]
Common Mistakes:
  • Thinking it concatenates the list
  • Expecting nested lists
  • Assuming error on multiplication

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes