0
0
NumPydata~20 mins

Why math functions matter in NumPy - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Math Functions Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of numpy math function on array
What is the output of this code snippet using numpy's sqrt function on an array?
NumPy
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.0 4.0 9.0 16.0]
D[0. 2. 3. 4.]
Attempts:
2 left
💡 Hint
Remember that np.sqrt calculates the square root element-wise and returns floats.
data_output
intermediate
2:00remaining
Result of applying numpy log function
What is the output array when applying numpy's natural log function to this array?
NumPy
import numpy as np
arr = np.array([1, np.e, np.e**2])
result = np.log(arr)
print(result)
A[1. 2. 3.]
B[1. 1. 1.]
C[0. 2. 4.]
D[0. 1. 2.]
Attempts:
2 left
💡 Hint
Recall that log(e) = 1 and log(e^2) = 2.
visualization
advanced
3:00remaining
Visualizing the effect of numpy sin function
Which plot correctly shows the sine values for angles from 0 to 2π using numpy?
NumPy
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
plt.plot(x, y)
plt.title('Sine Wave')
plt.show()
AA smooth wave starting at 0, rising to 1 at π/2, back to 0 at π, down to -1 at 3π/2, and back to 0 at 2π
BA straight line increasing from 0 to 2π
CA wave starting at 1, going down to -1, then back to 1
DA flat line at y=0
Attempts:
2 left
💡 Hint
The sine function starts at 0 and oscillates between -1 and 1 over 0 to 2π.
🧠 Conceptual
advanced
2:00remaining
Why use numpy math functions over Python math module?
Which reason best explains why numpy math functions are preferred for arrays over Python's math module?
APython math module functions are faster for arrays than numpy functions.
BNumpy functions operate element-wise on arrays efficiently, while math module functions only work on single numbers.
CNumpy functions require less memory but cannot handle arrays.
DPython math module supports GPU acceleration, numpy does not.
Attempts:
2 left
💡 Hint
Think about how numpy handles many numbers at once.
🔧 Debug
expert
3:00remaining
Identify the error in numpy math function usage
What error will this code raise and why? import numpy as np arr = np.array([-1, 0, 1]) result = np.sqrt(arr) print(result)
NumPy
import numpy as np
arr = np.array([-1, 0, 1])
result = np.sqrt(arr)
print(result)
ATypeError: unsupported operand type(s) for sqrt
BValueError: math domain error
CRuntimeWarning: invalid value encountered in sqrt, result contains nan for negative input
DNo error, output is [nan 0. 1.]
Attempts:
2 left
💡 Hint
Square root of negative numbers is not defined for real numbers.