SciPy vs NumPy
While NumPy and SciPy are closely related, the best way to understand them is to see them in action.
This lesson will walk you through using NumPy for basic computation and then SciPy for an advanced task.
Installing and Importing SciPy
If you’re running this in a Jupyter Lite environment, make sure to install SciPy before importing:
import piplite await piplite.install('scipy')
Once installed:
import numpy as np from scipy import stats
Example: Mean and t-Test
Let’s say you have two datasets and want to compare their means.
Using NumPy for the mean:
data1 = [5.1, 5.5, 5.8, 6.0, 6.2] data2 = [5.0, 5.1, 5.4, 5.6, 5.9] mean1 = np.mean(data1) mean2 = np.mean(data2) print("Mean of data1:", mean1) print("Mean of data2:", mean2)
Using SciPy for a statistical test:
t_stat, p_value = stats.ttest_ind(data1, data2) print("t-statistic:", t_stat) print("p-value:", p_value)
With NumPy, you can compute the means. With SciPy, you can directly test whether those means are statistically different — without writing the math yourself.
Key Takeaway
NumPy handles the core math and array operations, while SciPy gives you ready-made scientific and statistical tools to solve complex problems faster.
SciPy is primarily used for basic arithmetic operations, similar to those handled by NumPy.
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help