SciPy is the Python library for scientific algorithms that go beyond array creation and basic numerical operations. It builds on NumPy and provides focused tools for optimization, integration, statistics, signal processing, sparse data, and other mathematical tasks.
I checked SciPy’s current user guide to separate the package’s job from NumPy’s. I ran a small optimization, an integral, and a statistical test so the examples show their actual return values. I verified them in a fresh Python 3.14.7 environment with SciPy 1.18.1 and NumPy 2.5.3.
What SciPy adds to NumPy
NumPy gives Python its core multidimensional array and the operations used to build, select, reshape, and calculate with numeric data. SciPy uses that array foundation and adds algorithms for problems such as finding a minimum, estimating an integral, testing a statistical hypothesis, or filtering a signal. You can use both in the same program.
| Library | Use it for | Common object or tools |
|---|---|---|
| NumPy | Numeric arrays and basic array operations | numpy.ndarray, np.mean() |
| SciPy | Scientific algorithms that operate on numeric inputs | scipy.optimize, scipy.integrate, scipy.stats |
| pandas | Labeled columns, rows, and tabular data work | Series, DataFrame |
The boundary depends on the task, not a contest between libraries. Use NumPy to prepare an array, SciPy when you need a numerical method, and pandas when labels and table operations help you handle the data. SciPy does not replace NumPy, and pandas can work alongside both.
The SciPy project includes subpackages for linear algebra, integration, statistics, optimization, signal processing, interpolation, sparse arrays, and more. The official user guide lists the current areas. You import the subpackage that owns the function you need.
What you need before using SciPy
Use a supported Python installation and a project environment so the package is installed for the interpreter that runs your code. A working knowledge of Python functions and NumPy arrays helps, but you do not need to learn every SciPy subpackage first. The official installation guide recommends a virtual environment for pip-based projects.
SciPy depends on NumPy, and pip installs a compatible NumPy dependency when needed. Before you install, choose the project’s Python environment, know which interpreter or notebook kernel will run your code, and use one package manager, either pip or conda.
- Choose the project’s Python environment.
- Know which interpreter or notebook kernel runs your code.
- Use one package manager, either pip or conda.
How to install and try SciPy
Install the package into the environment you will run, verify the import, then pick a subpackage for the calculation.
Install it in the environment you use
Create and activate a virtual environment for the project, then run this command with that environment’s Python:
python -m pip install scipy
Run the version check from the same terminal or notebook kernel where you will run the program:
python -c "import scipy; print(scipy.__version__)"
Run the version check in the interpreter you use. The output confirms SciPy imports there and prints its version, while the AskPython installation tutorial covers platform-specific setup.
Import the subpackage for the task
Use the subpackage name as part of the import. These imports keep the source of each function visible:
import numpy as np
from scipy.integrate import quad
from scipy.optimize import minimize_scalar
from scipy import stats
Use np for array operations that belong to NumPy, then call a SciPy routine for its algorithm. SciPy modules have their own namespaces, such as scipy.integrate and scipy.optimize.
The SciPy subpackage overview maps the available modules when you are unsure where a function lives.
Run a small optimization
For a one-variable function, minimize_scalar() searches within the supplied bounds. This quadratic has its minimum at x = 4:
from scipy.optimize import minimize_scalar
result = minimize_scalar(
lambda x: (x - 4) ** 2 + 3,
bounds=(0, 10),
method="bounded",
)
print(f"Minimum: x={result.x:.3f}, f(x)={result.fun:.3f}, success={result.success}")
The result was x=4.000, f(x)=3.000, and success=True. I chose minimize_scalar() because this example has one variable and known bounds. I checked the success flag too, because a returned number by itself does not tell you whether the solver finished successfully.
Inspect result.message and the bounds before relying on a result. This method finds a minimum for the bounded one-dimensional problem, not a universal global minimum for every function.
For several variables or constraints, use scipy.optimize.minimize() and choose a method that matches the problem. The SciPy minimize tutorial covers those options.
Estimate an integral
quad() numerically estimates a definite integral and returns both the estimate and an estimate of the absolute error:
from scipy.integrate import quad
area, error = quad(lambda x: x**2, 0, 1)
print(f"Area: {area:.6f}; estimated error: {error:.2e}")
I ran quad() on x**2 from 0 to 1, and it returned approximately 0.333333 with an estimated error of 3.70e-15. The exact integral is one third.
That error comes from the numerical method, so it does not include every source of input or modeling error. See the quad example for more integration details.
Run a statistical test
scipy.stats includes hypothesis tests and probability distributions. Here, Welch’s independent two-sample t-test compares two sample means without assuming equal population variances:
from scipy import stats
group_a = [10, 12, 13, 11, 14]
group_b = [15, 16, 14, 18, 17]
result = stats.ttest_ind(group_a, group_b, equal_var=False)
print(f"statistic={result.statistic:.3f}, p-value={result.pvalue:.4f}")
I used equal_var=False to run Welch’s test, and I checked both returned values: statistic -4.000 and p-value 0.0039. The p-value is not the probability that the null hypothesis is true. Interpret it in light of the test’s assumptions and how the samples were collected.
The SciPy statistics tutorial explains more tests and distributions.
Why SciPy imports or results can surprise you
When a call fails or returns an unexpected result, check the interpreter, method assumptions, and meaning of the output before changing the code.
| Symptom | Check |
|---|---|
| Import error | Compare the interpreter used for install with the one running the script. |
| Unexpected optimization result | Inspect solver success, message, bounds, and local or global scope. |
| Unexpected statistical result | Check the test assumptions and how the sample was collected. |
The import fails after installation
ModuleNotFoundError: No module named ‘scipy’ often means installation and execution use different Python environments. Run python -m pip show scipy and python -c “import scipy” with the same python command that starts your program. In a notebook, check the kernel’s interpreter too.
Using python -m pip ties installation to the interpreter named by python. A standalone pip command can target a different environment.
The optimizer returns a result you did not expect
Optimization methods have assumptions, bounds, stopping criteria, and success states. A local solver can return a local minimum rather than the lowest value over the entire domain. Check result.success, result.message, the starting point, and the bounds.
If the question is one-dimensional, minimize_scalar() is usually a clearer starting point than the general minimize() interface.
A p-value is not the whole conclusion
A statistical test cannot repair a biased sample or decide whether an effect matters in practice. Pick a test whose assumptions match the data, report the statistic and context, and treat the p-value as one result rather than a verdict on its own.
Pick the SciPy module that matches the calculation
SciPy is the place to look when an array is ready and the next step is a numerical algorithm. Choose a starting point from the task:
I start with the calculation rather than the library name. If the next operation is a numerical integral, import that routine directly and keep NumPy for the array work around it.
python -c "from scipy.integrate import quad; print(quad(lambda x: x**2, 0, 1)[0])"
SciPy questions beginners ask
What is SciPy used for?
SciPy provides numerical algorithms for scientific and technical tasks such as optimization, integration, statistics, linear algebra, signal processing, interpolation, and sparse arrays.
What is the difference between NumPy and SciPy?
NumPy provides arrays and core numerical operations. SciPy builds on NumPy and adds higher-level scientific algorithms, such as numerical integration and optimization.
Does SciPy include NumPy?
SciPy depends on NumPy, and installing SciPy with pip installs NumPy as a dependency if it is not already available. Import NumPy explicitly when your code uses NumPy functions.
Is SciPy faster than NumPy?
There is no blanket speed ranking. SciPy provides algorithms that NumPy does not, and performance depends on the operation, data, and installed numerical libraries. Measure the specific workload before drawing a speed conclusion.
Is SciPy the same as pandas?
No. SciPy supplies scientific algorithms, NumPy provides the core array operations, and pandas provides labeled Series and DataFrame structures for tabular data. They can be used together.

