Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q13 of 15
NumPy - Array Operations
What is the output of the following code?
import numpy as np
arr = np.array([1, 4, 9, 16])
result = np.sqrt(arr)
print(result)
A[1. 2. 3. 4.]
B[1 2 3 4]
C[1. 4. 9. 16.]
D[0. 2. 3. 4.]
Step-by-Step Solution
Solution:
  1. Step 1: Understand np.sqrt on array elements

    Applying np.sqrt on each element: sqrt(1)=1.0, sqrt(4)=2.0, sqrt(9)=3.0, sqrt(16)=4.0.
  2. Step 2: Check output format

    NumPy returns floats for sqrt, so output is [1. 2. 3. 4.].
  3. Final Answer:

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

    np.sqrt([1,4,9,16]) = [1. 2. 3. 4.] [OK]
Quick Trick: Square root returns floats, watch decimal points [OK]
Common Mistakes:
  • Expecting integer output instead of float
  • Confusing np.sqrt with np.square
  • Misreading array output format

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes