numpy, matplotlib, scipy, Pillow, OpenCV, PyTorch — the ready-made toolboxes that turn heavy math and data work into a single import. You pick the tool; the AI writes the code.
← / → to navigate · EN/VI switch below
The hard parts — fast math on big data, plotting, image processing, neural networks — are already written, battle-tested, and free. You import them; you don't build them.
Fast math on a million numbers, drawing charts, editing images, training neural networks — each is a mature, battle-tested library.
import numpy gives fast arrays; from PIL import Image gives image editing; import torch gives deep learning. The import line tells you the job of the whole file.
You don't memorize thousands of functions. You know which library does what, then you ask the AI for code and check the result.
NumPy is the base; the others build on or beside it. Knowing the layering explains why some libraries feel fast, some scientific, some visual.
This deck is a job map. Each library gets one clear job and a tiny taste of its API — just enough to recognize it in code the AI hands you.
No memorizing APIs, no writing matrix math by hand, no understanding how a neural network trains internally. Those are the library's job — and the AI's job.
A map of six jobs: arrays, charts, science, images, vision, deep learning. When a problem lands, you name the job, pick the library, and hand the rest to the AI.
Every library in this deck follows the same three steps. The aliases (np, plt, cv2, torch) are conventions — you'll recognize them everywhere.
# first time on this machine: install (projects list this in requirements.txt)
# pip install numpy pillow matplotlib
# every file that uses them starts like this:
import numpy as np # alias: np
from PIL import Image # pull in the Image class
import matplotlib.pyplot as plt # alias: plt
print(np.mean([1, 2, 3])) # 2.0 — toolbox, ready
requirements.txt in real projects is just a list of pip installs. If an AI answer starts with an import you don't know, that's your first question: 'what does this do?'
The foundation of the whole data stack: fast arrays and vectorized math. Everything else speaks its language.
NumPy's job is one: hold numbers in a grid and do math on the whole grid at once.
A fast, fixed-size grid of numbers: one row, a table, or a whole image (rows × cols × 3). Python's lists, but arranged for speed.
a * b multiplies two arrays element by element in one line — no loops. That's the 'fast': C-speed math over millions of numbers.
Matplotlib, SciPy, OpenCV and PyTorch all exchange data as NumPy arrays. Read one [rows, cols] array and you can read most of the data stack.
The essence of NumPy: describe the whole operation, not each element. That's the vectorized way.
import numpy as np
a = np.array([1, 2, 3, 4])
b = np.array([10, 20, 30, 40])
print(a * b) # [ 10 40 90 160] ← element by element
print(a.sum()) # 10
print(a.mean()) # 2.5
# an image = one array: rows × cols × 3 color channels
pixels = np.zeros((100, 100, 3))
np.array builds the array; .sum(), .mean() are the everyday calls. Line 11 is the kicker: an entire image is just one array.
total = 0; for x in a: total = total + x — Python checks types and bounds element by element. Fine for 100 numbers, painful for 10 million.
a.sum() — one call, the whole array processed at C speed. Same result, often 100× faster. The array is the point; the loop disappears.
The classic plotting library: from a list of numbers to a shareable chart in three calls.
The fastest route from 'list of numbers' to 'chart I can share'.
Give it two lists (x, y) and it draws a line. Bars, scatter, histograms — the standard ways to look at numbers.
import matplotlib.pyplot as plt is the convention you'll see everywhere: plt.plot, plt.bar, plt.title, plt.show.
As a shipper you'll mostly look at the chart it produces — and occasionally ask the AI to tweak: 'make it a bar chart', 'add a title', 'export to PNG'.
The whole API is 'describe the picture': the data, the style, the window.
import matplotlib.pyplot as plt
days = [1, 2, 3, 4, 5]
signups = [12, 19, 17, 28, 35]
plt.plot(days, signups) # draw the line
plt.title("Daily signups")
plt.show() # open the window
Three calls and a chart exists. This exact shape shows up in every data analysis you'll ever review.
Statistics, optimization, signals, linear algebra — the serious-math shelf, built on NumPy arrays.
SciPy = scientific computing on top of NumPy. Same arrays in and out, but with the hard formulas already inside.
Distribution math: mean, std, confidence intervals, hypothesis tests. When you ask 'is this result significant?', the answer comes from here.
Find the best parameters: minimize a cost, fit a curve to data. The engine behind 'make the model fit'.
Frequencies and filters: clean a noisy sensor signal, find the dominant frequency. The audio and vibration toolkit.
Linear algebra beyond NumPy's basics: decompositions, eigenvalues. The heavy-duty math shelf — all speaking NumPy arrays.
SciPy takes lists or arrays and gives back numbers — the same data, one more level of math.
from scipy import stats
temps = [21.5, 22.1, 20.9, 23.0, 22.4, 21.8, 22.6]
d = stats.describe(temps)
print(d.mean) # 22.1 — the average
print(d.std) # 0.6 — how much it varies
print(d.min, d.max) # 20.9 23.0
One describe() call hands you the full statistical summary of a dataset. No loops, no formulas.
The everyday image toolkit: open, resize, crop, convert, save. The one your web app will actually use.
Pillow (PIL) does the boring 95% of image work: open it, tweak it, save it. No GPU, no model — just fast, reliable pixels.
Image.open('a.jpg') reads almost any format — JPEG, PNG, WebP, GIF; .save() writes it back. The workhorse of any image endpoint.
img.resize((200, 200)) sets an exact size; img.thumbnail((200, 200)) shrinks while keeping the ratio. The two calls behind every 'upload a photo' feature.
img.crop((x1, y1, x2, y2)) cuts a region; img.convert('L') switches to grayscale. Compose them into real image pipelines.
Avatars, product photos, generated thumbnails, uploaded files — for a VPS web app, Pillow is the image library you'll meet first and use most.
Everything else (crop, rotate, filters) is the same shape: open it, call a method, save it.
from PIL import Image
img = Image.open("photo.jpg") # open it
img = img.resize((400, 400)) # new size
thumb = img.copy()
thumb.thumbnail((100, 100)) # keep ratio
img.save("out.jpg") # save it
print(img.size) # (400, 400)
Eight lines, and a photo is resized, thumbnailed and saved — the core of most 'image upload' features.
Image and video processing at scale: filters, transforms, detection — let the computer see.
Image and video processing at scale — filters, transforms, and detection, frame by frame.
Blur, threshold, edge detection, rotation — implemented in optimized C, so it stays fast on big images and whole video streams.
Find faces, corners, contours; match shapes. The classical-vision toolkit — what came before deep learning took over.
import cv2 is the convention. One quirk to remember: it reads images as BGR (blue–green–red), not RGB — a classic source of color bugs.
The shape: load an image, transform it, detect something. That's the whole vocabulary.
import cv2
img = cv2.imread("street.jpg") # loads as a NumPy array!
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (5, 5), 0)
faces = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
found = faces.detectMultiScale(gray, 1.1)
print(len(found), "faces found")
Line 3 is the layering in action: OpenCV hands you a NumPy array. Filters and detection are single calls on that array.
The deep learning framework: tensors, autograd, and the training loop behind every AI model.
The deep learning framework: tensors, automatic gradients, and the loop that trains models.
Like NumPy arrays, but they also live on GPUs: torch.tensor([1, 2, 3]). The data type of deep learning.
PyTorch records your math as you compute, so it can compute gradients — 'how much should each weight change'. That signal makes training possible.
A model is a chain of tensor operations; training is thousands of steps of predict → measure error → nudge weights. Every LLM and image model is made this way.
You'll rarely write this yourself — but recognizing 'this is training a model' is the skill.
import torch
x = torch.tensor([1.0, 2.0, 3.0], requires_grad=True)
y = (x * x).sum() # 1 + 4 + 9 = 14
y.backward() # compute the gradient
print(x.grad) # [2. 4. 6.] ← d(x²)/dx = 2x
A model in embryo: a computation, and the gradient that says which way to adjust. Training = repeat this, thousands of steps, at scale.
The deck in one view: who sits on whom, which job belongs to which library, and what you'll actually use.
When a library says 'works with arrays', it means NumPy arrays. Data flows down: your app calls a high-level function, which does fast NumPy math underneath.
your app → high-level call → fast NumPy math underneath
Memorize the import lines, not the functions — the import is the job description.
| Library | Its one job | You'll spot it when |
|---|---|---|
| NumPy | Fast multi-dimensional arrays & vectorized math | import numpy as np — most data stacks start here |
| Matplotlib | Charts: lines, bars, histograms from data | import matplotlib.pyplot as plt |
| SciPy | Stats, optimization, signals, linear algebra | from scipy import stats / optimize |
| Pillow | Everyday images: open, resize, crop, convert | from PIL import Image |
| OpenCV | Vision: filters, detection, video frames | import cv2 |
| PyTorch | Deep learning: tensors, autograd, training | import torch |
Most projects never touch the heavy stack — and that's correct. Match the tool to the job.
Uploads, avatars, thumbnails, generated images: Pillow is the workhorse. Small install, fast, fits a VPS perfectly.
Analyze a CSV export, chart a decision: NumPy does the math, Matplotlib makes it visible. SciPy joins when the math gets scientific.
Specific projects only: detect objects (OpenCV) or run models (PyTorch — often via an API, not on your VPS). Know they exist; that's enough.
The same four moves you use everywhere in this course — now pointed at library code.
Tell the AI the outcome: 'resize uploaded photos to 400px and save thumbnails.' The job picks the library — Pillow, in this case.
The first line of any AI answer: what does it import? from PIL import Image → image job. import torch → heavy ML job — question why.
Pillow is a tiny install; PyTorch is gigabytes with a GPU stack. Ask what it must pip install before you say yes — on a VPS, disk and RAM are real.
Save the result and look: a thumbnail at the right size, a chart with the right numbers, a gradient of [2. 4. 6.]. Output is the truth.
Six libraries, one habit: know the job of each, and let the AI do the rest.
Next: put these to work in a real project. Unfamiliar import? You know the move: name the job, check the install cost, run the output.