Challenge - 5 Problems
SciPy Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of SciPy integration
What is the output of this code that uses SciPy to integrate a simple function?
SciPy
from scipy.integrate import quad def f(x): return x**2 result, error = quad(f, 0, 1) print(round(result, 3))
Attempts:
2 left
💡 Hint
Think about the integral of x squared from 0 to 1.
✗ Incorrect
The integral of x^2 from 0 to 1 is 1/3, which is approximately 0.333.
❓ data_output
intermediate2:00remaining
Result of SciPy root finding
What is the value of root found by SciPy's root_scalar for the function f(x) = x^3 - 1 near x=1?
SciPy
from scipy.optimize import root_scalar def f(x): return x**3 - 1 sol = root_scalar(f, bracket=[0, 2]) print(round(sol.root, 3))
Attempts:
2 left
💡 Hint
The cube root of 1 is?
✗ Incorrect
The root of x^3 - 1 = 0 is x = 1, so the root_scalar finds 1.000.
❓ visualization
advanced3:00remaining
Plotting a Gaussian PDF with SciPy
Which option produces the correct plot of a Gaussian probability density function (PDF) using SciPy?
SciPy
import numpy as np import matplotlib.pyplot as plt from scipy.stats import norm x = np.linspace(-3, 3, 100) # Plot code here plt.plot(x, norm.pdf(x)) plt.title('Gaussian PDF') plt.show()
Attempts:
2 left
💡 Hint
The normal distribution has one peak at the mean.
✗ Incorrect
The norm.pdf function returns the Gaussian PDF values, which form a bell-shaped curve centered at 0.
🧠 Conceptual
advanced1:30remaining
Understanding SciPy's optimize.minimize output
After running SciPy's optimize.minimize on a function, what does the 'success' attribute in the result indicate?
Attempts:
2 left
💡 Hint
Think about what success means in optimization.
✗ Incorrect
The 'success' attribute is a boolean that tells if the optimizer successfully found a solution.
🔧 Debug
expert2:30remaining
Identify the error in this SciPy interpolation code
What error will this code raise when run?
SciPy
import numpy as np from scipy.interpolate import interp1d x = np.array([0, 1, 2]) y = np.array([0, 1]) f = interp1d(x, y) print(f(1.5))
Attempts:
2 left
💡 Hint
Check the lengths of x and y arrays.
✗ Incorrect
interp1d requires x and y arrays to have the same length. Here y has length 2 but x has length 3.