Learn SciPy

SciPy is an open-source Python library, built directly on top of NumPy, that adds hundreds of ready-made algorithms for scientific and technical computing.

What SciPy Is For

NumPy gives you fast, multi-dimensional arrays and the basic math you can do with them. SciPy takes that foundation and layers specialized, well-tested numerical routines on top of it: optimization, integration, interpolation, linear algebra, signal processing, statistics, and more. Instead of writing your own root-finder or matrix solver from scratch, you call a SciPy function that has been refined and battle-tested for decades.

  • scipy.optimize - minimizing functions and solving equations
  • scipy.linalg - linear algebra beyond what NumPy offers
  • scipy.constants - physical and mathematical constants
  • scipy.sparse - matrices that are mostly zeros
  • scipy.stats - probability distributions and statistical tests
  • scipy.integrate - numerical integration and solving differential equations

SciPy Is Organized Into Subpackages

Unlike a single flat library, SciPy is split into topic-specific subpackages. Each one focuses on a narrow area of numerical computing, and you import only the ones you need. This keeps the top-level scipy namespace small - importing scipy by itself does not give you access to scipy.optimize or scipy.sparse; you import each subpackage explicitly.

Importing a Subpackage

import numpy as np
from scipy import constants, linalg

# NumPy supplies the array
radius = np.array([1, 2, 3])

# SciPy supplies the specialized constant (pi) and routine (det)
circumference = 2 * constants.pi * radius
print(circumference)  # [ 6.28318531 12.56637061 18.84955592]

matrix = np.array([[1, 2], [3, 4]])
print(linalg.det(matrix))  # -2.0

Why Not Just Use NumPy?

NumPy focuses on arrays and the arithmetic you can do with them. It does not include, for example, a general-purpose function minimizer, a sparse matrix solver, or a library of probability distributions. SciPy fills those gaps with algorithms that wrap decades-old, heavily optimized Fortran and C libraries such as LAPACK and FFTPACK, so you get both convenience and performance.

A Quick Look at scipy.integrate

from scipy import integrate

# Integrate f(x) = x**2 from 0 to 3 -> exact value is 9.0
value, error_estimate = integrate.quad(lambda x: x**2, 0, 3)
print(value)  # 9.0
SubpackageTypical Use
scipy.optimizeMinimize a function or find where it equals zero
scipy.integrateCompute a definite integral or solve an ODE
scipy.sparseStore and operate on mostly-zero matrices
scipy.constantsLook up a physical constant or unit conversion

Where SciPy Fits In

SciPy sits in the same ecosystem as NumPy, pandas, and Matplotlib. A typical scientific Python workflow loads data with pandas or NumPy, processes or models it with SciPy, and visualizes results with Matplotlib. Because SciPy operates on NumPy arrays, it composes naturally with the rest of that stack without any special conversion steps.

Exercise: SciPy Introduction

What does the name "SciPy" refer to?

Frequently Asked Questions

What is the difference between NumPy and SciPy?
NumPy provides the array and the fast operations over it. SciPy builds scientific algorithms on top: optimisation, integration, interpolation, signal processing and statistical tests. You almost always use both, with NumPy underneath.
Do I need NumPy before SciPy?
Yes. Every SciPy function takes and returns NumPy arrays, so array creation, indexing, slicing and broadcasting are prerequisites rather than optional extras. Without them the function signatures and the shapes they expect will not make sense.
When should I use SciPy instead of writing the maths myself?
Almost always. Its routines are numerically careful in ways that hand-written versions usually are not, particularly around precision and edge cases. Write it yourself to learn the method, then use SciPy for anything that matters.