SciPy Tutorial
SciPy is a Python library for scientific and technical computing. Its name is short for Scientific Python.
SciPy is built on top of NumPy. NumPy gives you fast arrays, and SciPy adds ready-made tools for statistics, finding the best values (optimization), filling gaps in data (interpolation), calculus and much more.
Why Learn SciPy?
- It saves you from writing difficult maths code yourself; the tested functions are already there
- It is used by engineers, scientists, data analysts and machine learning libraries
- Its statistics module is great for real questions, like "is the new teaching method really better?"
- It works smoothly with NumPy and Pandas
A First Example
Find the lowest point of the curve y = (x - 3)² + 2:
Example
from scipy.optimize import minimize_scalar
result = minimize_scalar(lambda x: (x - 3) ** 2 + 2)
print(round(result.x, 4))
print(round(result.fun, 4))3.0 2.0
SciPy found that the curve is lowest at x = 3, where y = 2.
What You Will Learn
- Installing and importing SciPy, and its modules
- Scientific constants and unit conversion
- Descriptive statistics and probability distributions
- Hypothesis tests such as the t-test and correlation
- Optimization: finding minimums and roots
- Interpolation and integration
You should know basic Python and the basics of NumPy before you start.
Exercise
Which library is SciPy built on?
What to Learn After SciPy
Use Pandas to prepare real data for SciPy's tests, or try R, a language designed for statistics.
Want to learn with a teacher? The Workownix Python Programming course takes you from Python basics to data analysis projects, online or at our institute in Orangi Town, Karachi.
