0
0
SciPydata~20 mins

SciPy vs NumPy relationship - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SciPy vs NumPy Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding the relationship between SciPy and NumPy

Which statement best describes the relationship between SciPy and NumPy?

ASciPy is built on top of NumPy and extends its functionality with additional scientific computing tools.
BNumPy is a subset of SciPy that focuses only on matrix operations.
CNumPy is built on top of SciPy to provide basic array operations.
DSciPy and NumPy are completely independent libraries with no overlap in functionality.
Attempts:
2 left
💡 Hint

Think about which library provides the core array data structure and which adds more specialized functions.

Predict Output
intermediate
2:00remaining
Output of NumPy and SciPy array operations

What is the output of the following code?

SciPy
import numpy as np
from scipy import linalg

arr = np.array([[1, 2], [3, 4]])
inv_arr = linalg.inv(arr)
print(np.round(inv_arr, 2))
A[[ 0.5 0. ] [ 0. 0.5]]
B[[ 2. -1. ] [-1.5 0.5]]
C[[-2. 1. ] [ 1.5 -0.5]]
DRaises a TypeError because linalg.inv does not accept NumPy arrays
Attempts:
2 left
💡 Hint

Recall that linalg.inv computes the inverse of a matrix.

data_output
advanced
2:00remaining
Comparing mean calculation with NumPy and SciPy

Given the array data = np.array([1, 2, 3, 4, 5]), what is the output of the following code?

SciPy
import numpy as np
from scipy import stats

data = np.array([1, 2, 3, 4, 5])
mean_np = np.mean(data)
mean_scipy = stats.tmean(data)
print((mean_np, mean_scipy))
ARaises an AttributeError because stats.tmean is deprecated
B(3.0, 2.5)
C(2.5, 3.0)
D(3.0, 3.0)
Attempts:
2 left
💡 Hint

Both functions calculate the mean but may have different default behaviors.

visualization
advanced
2:30remaining
Plotting with NumPy and SciPy integration

Which option correctly creates a plot of a sine wave using NumPy for data and SciPy for signal processing?

SciPy
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal

x = np.linspace(0, 2 * np.pi, 100)
sine_wave = np.sin(x)
filtered_wave = signal.savgol_filter(sine_wave, 11, 3)
plt.plot(x, sine_wave, label='Original')
plt.plot(x, filtered_wave, label='Filtered')
plt.legend()
plt.show()
APlots two lines: the original sine wave and a smoothed version using Savitzky-Golay filter.
BPlots only the original sine wave without any filtering.
CRaises a NameError because signal.savgol_filter is not imported.
DPlots a cosine wave instead of sine due to a code mistake.
Attempts:
2 left
💡 Hint

Check how signal.savgol_filter is used to smooth data.

🔧 Debug
expert
2:30remaining
Identifying the error in combining SciPy and NumPy functions

What error does the following code produce?

SciPy
import numpy as np
from scipy import optimize

def f(x):
    return np.sin(x) + np.cos(x)

result = optimize.root(f, 0)
print(result.x)
ATypeError because optimize.root expects a list, not a function.
BNo error; prints the root near 0.
CValueError because the initial guess 0 is invalid.
DAttributeError because np.sin and np.cos are not recognized inside the function.
Attempts:
2 left
💡 Hint

Check how optimize.root works with functions and initial guesses.