0
0
SciPydata~20 mins

First SciPy computation - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SciPy Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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))
A0.500
B1.000
C0.333
D0.250
Attempts:
2 left
💡 Hint
Think about the integral of x squared from 0 to 1.
data_output
intermediate
2: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))
A0.000
B1.000
C-1.000
D2.000
Attempts:
2 left
💡 Hint
The cube root of 1 is?
visualization
advanced
3: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()
APlots a flat horizontal line
BPlots a straight line increasing from left to right
CPlots a curve with two peaks
DPlots a bell-shaped curve centered at 0
Attempts:
2 left
💡 Hint
The normal distribution has one peak at the mean.
🧠 Conceptual
advanced
1: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?
A'success' is True if the optimizer found a solution meeting the criteria
B'success' is the minimum value found by the optimizer
C'success' is the number of iterations performed
D'success' is the initial guess provided to the optimizer
Attempts:
2 left
💡 Hint
Think about what success means in optimization.
🔧 Debug
expert
2: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))
AValueError: x and y must have same length
BTypeError: unsupported operand type(s)
CIndexError: index out of range
DNo error, prints 1.5
Attempts:
2 left
💡 Hint
Check the lengths of x and y arrays.