Challenge - 5 Problems
Square Root Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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)
Attempts:
2 left
💡 Hint
np.sqrt() returns floating point numbers even if input is integers.
✗ Incorrect
np.sqrt() calculates the square root element-wise and returns floats. So the output is an array of floats: [1. 2. 3. 4.]
❓ data_output
intermediate2: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)
Attempts:
2 left
💡 Hint
np.sqrt keeps the shape of the input array and returns floats.
✗ Incorrect
The input is a 2x2 array. np.sqrt returns the square root element-wise, keeping the shape (2,2) and converting values to floats.
🔧 Debug
advanced2: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)
Attempts:
2 left
💡 Hint
Square root of negative numbers is not defined in real numbers, numpy returns nan with a warning.
✗ Incorrect
np.sqrt on negative values returns nan and raises a RuntimeWarning about invalid value encountered.
🧠 Conceptual
advanced1: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?Attempts:
2 left
💡 Hint
Square roots often produce decimal numbers, so output must support decimals.
✗ Incorrect
np.sqrt converts integer inputs to floats because square roots can be decimal numbers.
🚀 Application
expert2:30remaining
Using np.sqrt() to normalize data
You have a numpy array of positive values representing counts:
You want to apply square root transformation to reduce skewness before analysis.
Which code snippet correctly applies this transformation and stores the result in
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?Attempts:
2 left
💡 Hint
Square root transformation means applying np.sqrt directly.
✗ Incorrect
Applying np.sqrt reduces skewness by compressing large values more than small ones.