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([3, 6, 9])
result = arr ** 2
print(result)
A[9 36 81]
B[6 12 18]
C[3 6 9]
DError: unsupported operand
Step-by-Step Solution
Solution:
  1. Step 1: Understand exponentiation of array by scalar

    Using '** 2' squares each element in the array.
  2. Step 2: Calculate squares of each element

    3^2=9, 6^2=36, 9^2=81, so result is [9, 36, 81].
  3. Final Answer:

    [9 36 81] -> Option A
  4. Quick Check:

    Scalar exponentiation = element-wise power [OK]
Quick Trick: Use '**' operator to raise array elements to a power [OK]
Common Mistakes:
  • Confusing multiplication with exponentiation
  • Expecting original array
  • Expecting error on power operation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes