SciPy helps you solve math and science problems by giving you many tools organized in groups. This makes it easy to find and use the right tool for your task.
SciPy module organization
import scipy # Access submodules like: scipy.integrate scipy.optimize scipy.stats scipy.linalg scipy.signal scipy.interpolate scipy.special
SciPy is divided into submodules, each for a specific type of task.
You import SciPy as a whole, then use the submodules to access functions.
import scipy result = scipy.integrate.quad(lambda x: x**2, 0, 1) print(result)
from scipy import optimize root = optimize.root_scalar(lambda x: x**2 - 4, bracket=[0, 3]) print(root.root)
import scipy.stats as stats mean, var = stats.norm.stats(moments='mv') print(f"Mean: {mean}, Variance: {var}")
This program shows how to use three SciPy submodules: integrate, optimize, and stats. It calculates an integral, finds a root, and gets statistics from a normal distribution.
import scipy # Calculate the integral of x^3 from 0 to 2 integral_result = scipy.integrate.quad(lambda x: x**3, 0, 2) # Find the root of x^2 - 5 = 0 between 0 and 3 root_result = scipy.optimize.root_scalar(lambda x: x**2 - 5, bracket=[0, 3]) # Get mean and variance of a normal distribution mean, var = scipy.stats.norm.stats(moments='mv') print(f"Integral of x^3 from 0 to 2: {integral_result[0]:.4f}") print(f"Root of x^2 - 5 = 0: {root_result.root:.4f}") print(f"Normal distribution mean: {mean:.4f}, variance: {var:.4f}")
Each submodule in SciPy focuses on a specific area, so you only use what you need.
Functions in SciPy often return multiple values; check the documentation to understand them.
Importing only needed submodules can make your code cleaner and faster.
SciPy is organized into submodules like integrate, optimize, stats, and more.
This organization helps you find the right tools for math and science tasks easily.
Using submodules correctly makes your data science work simpler and clearer.