0
0
NumPydata~20 mins

np.sqrt() for square roots in NumPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Square Root Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of np.sqrt() on a 1D array
What is the output of this code?
import numpy as np
arr = np.array([1, 4, 9, 16])
result = np.sqrt(arr)
print(result)
NumPy
import numpy as np
arr = np.array([1, 4, 9, 16])
result = np.sqrt(arr)
print(result)
A[1 4 9 16]
B[1 2 3 4]
C[1.0 2.0 3.0 4.0]
D[1. 2. 3. 4.]
Attempts:
2 left
💡 Hint
np.sqrt() returns floating point numbers even if input is integers.
data_output
intermediate
2:00remaining
Shape and values after np.sqrt() on 2D array
Given this code, what is the shape and content of result?
import numpy as np
arr = np.array([[4, 9], [16, 25]])
result = np.sqrt(arr)
print(result.shape)
print(result)
NumPy
import numpy as np
arr = np.array([[4, 9], [16, 25]])
result = np.sqrt(arr)
print(result.shape)
print(result)
A
(2, 2) and [[4. 9.]
 [16. 25.]]
B(4,) and [2. 3. 4. 5.]
C
(2, 2) and [[2. 3.]
 [4. 5.]]
D
(2, 2) and [[2 3]
 [4 5]]
Attempts:
2 left
💡 Hint
np.sqrt keeps the shape of the input array and returns floats.
🔧 Debug
advanced
2:00remaining
Error when applying np.sqrt() to negative numbers
What error or warning does this code produce?
import numpy as np
arr = np.array([-1, 4, 9])
result = np.sqrt(arr)
print(result)
NumPy
import numpy as np
arr = np.array([-1, 4, 9])
result = np.sqrt(arr)
print(result)
A
RuntimeWarning: invalid value encountered in sqrt
[nan 2. 3.]
BValueError: math domain error
CTypeError: unsupported operand type(s) for sqrt
D[-1. 2. 3.]
Attempts:
2 left
💡 Hint
Square root of negative numbers is not defined in real numbers, numpy returns nan with a warning.
🧠 Conceptual
advanced
1:30remaining
Understanding np.sqrt() output type
If you apply np.sqrt() to an integer numpy array, what is the data type of the output array?
AFloat type array
BInteger type array
CBoolean type array
DComplex type array
Attempts:
2 left
💡 Hint
Square roots often produce decimal numbers, so output must support decimals.
🚀 Application
expert
2:30remaining
Using np.sqrt() to normalize data
You have a numpy array of positive values representing counts:
counts = np.array([1, 4, 9, 16, 25])

You want to apply square root transformation to reduce skewness before analysis.
Which code snippet correctly applies this transformation and stores the result in transformed?
Atransformed = counts ** 2
Btransformed = np.sqrt(counts)
Ctransformed = np.square(counts)
Dtransformed = np.sqrt(counts) * 2
Attempts:
2 left
💡 Hint
Square root transformation means applying np.sqrt directly.