Bird
Raised Fist0
SciPydata~20 mins

First SciPy computation - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of the SciPy library in Python?
easy
A. To manage databases
B. To create web applications
C. To perform scientific and mathematical computations easily
D. To design user interfaces

Solution

  1. Step 1: Understand SciPy's role

    SciPy is designed for scientific and mathematical computations. Options for managing databases, creating web applications, and designing user interfaces do not match.
  2. Final Answer:

    To perform scientific and mathematical computations easily -> Option C
  3. Quick Check:

    SciPy = scientific math library [OK]
Hint: SciPy is for science and math, not web or UI [OK]
Common Mistakes:
  • Confusing SciPy with web frameworks
  • Thinking SciPy manages databases
  • Assuming SciPy is for UI design
2. Which of the following is the correct way to import the SciPy square root function?
easy
A. from scipy import sqrt
B. from scipy.special import sqrt
C. from scipy import math.sqrt
D. from scipy import sqrt as sp_sqrt

Solution

  1. Step 1: Recall SciPy import syntax

    sqrt is in scipy.special, so from scipy.special import sqrt works. Direct from scipy import sqrt fails as sqrt is not in top-level scipy (A,D); math.sqrt is separate module (B).
  2. Final Answer:

    from scipy.special import sqrt -> Option B
  3. Quick Check:

    from scipy.special import sqrt [OK]
Hint: Use scipy.special for sqrt [OK]
Common Mistakes:
  • Importing sqrt directly from scipy
  • Using incorrect module paths
  • Trying to import math.sqrt from scipy
3. What is the output of this code?
import numpy as np
from scipy import special
x = np.array([0, 1, 2])
y = special.expit(x)
print(y)
medium
A. [0.5 0.73105858 0.88079708]
B. [1. 2. 7.3890561]
C. [0. 1. 2.]
D. [0. 0.5 0.75]

Solution

  1. Step 1: Understand special.expit function

    special.expit computes sigmoid 1 / (1 + exp(-x)): sigmoid(0)=0.5, sigmoid(1)≈0.73105858, sigmoid(2)≈0.88079708 matching [0.5 0.73105858 0.88079708].
  2. Final Answer:

    [0.5 0.73105858 0.88079708] -> Option A
  3. Quick Check:

    sigmoid([0,1,2]) = [0.5 0.73105858 0.88079708] [OK]
Hint: expit = sigmoid function, check values at 0,1,2 [OK]
Common Mistakes:
  • Confusing expit with exponential
  • Expecting raw input array as output
  • Mixing up output with other functions
4. Identify the error in this code snippet:
from scipy import sqrt
result = sqrt(16)
print(result)
medium
A. print statement syntax is incorrect
B. sqrt function requires two arguments
C. Missing numpy import for sqrt
D. sqrt is not directly in scipy, import from scipy.special

Solution

  1. Step 1: Check import correctness

    sqrt is not in top-level scipy (needs scipy.special); function takes one argument; no numpy required; print is correct.
  2. Final Answer:

    sqrt is not directly in scipy, import from scipy.special -> Option D
  3. Quick Check:

    Import path error = sqrt is not directly in scipy, import from scipy.special [OK]
Hint: sqrt is in scipy.special, not scipy directly [OK]
Common Mistakes:
  • Assuming sqrt is in scipy root module
  • Thinking sqrt needs multiple arguments
  • Confusing print syntax with Python 2
5. You want to compute the Bessel function of the first kind for values [0, 1, 2] using SciPy. Which code snippet correctly does this?
hard
A. from scipy.special import jv import numpy as np x = np.array([0,1,2]) result = jv(0, x) print(result)
B. import scipy x = [0,1,2] result = scipy.bessel(0, x) print(result)
C. from scipy import bessel x = [0,1,2] result = bessel.jv(0, x) print(result)
D. from scipy.special import jn x = [0,1,2] result = jn(x, 0) print(result)

Solution

  1. Step 1: Identify correct function and import

    Bessel function of first kind: jv(order, x) from scipy.special. Code with from scipy.special import jv, np.array x, jv(0, x) works; others have wrong imports/functions/arguments.
  2. Final Answer:

    from scipy.special import jv import numpy as np x = np.array([0,1,2]) result = jv(0, x) print(result) -> Option A
  3. Quick Check:

    jv(0, x) from scipy.special [OK]
Hint: Use jv(order, x) from scipy.special for Bessel function [OK]
Common Mistakes:
  • Using wrong function names like bessel or jn incorrectly
  • Swapping arguments order in jn or jv
  • Not importing numpy for array input
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard