5.4.8 · D1Scientific Computing (Python)

Foundations — SciPy — overview of submodules

1,856 words8 min readBack to topic

Below we build every symbol and word the parent note leans on, starting from absolutely nothing. Read top to bottom: each idea is used only after it is drawn.


0. The array — the raw material

Before any algorithm, there is the thing the algorithm works on.

Figure — SciPy — overview of submodules

Why the topic needs it: every SciPy function takes arrays in and gives arrays out. When the parent writes A = np.array([[3,1],[1,2]]), that is a 2×2 array — 2 rows, 2 columns. b = np.array([9,8]) is a 1-D array of length 2. If you cannot picture these grids, nothing downstream makes sense.


1. The function — a machine that turns a number into a number

The parent writes things like lambda x: x**2 and . What is ?

  • fed returns . Fed returns .
  • fed returns — this will matter.

The picture: plot every pair as a point and join them → you get a curve. The curve is the function drawn.

Figure — SciPy — overview of submodules

Why the topic needs it: quad integrates a function, minimize finds the low point of a function. The function is the object every algorithm chews on.


2. Area under a curve — the symbol

The parent's first derivation is integration. Every piece of that scary symbol has a plain meaning.

Figure — SciPy — overview of submodules

Why a sum of rectangles? A rectangle's area is height × width. We can't measure a curved region directly, so we chop it into many thin rectangles, add them, and shrink the width toward zero. That shrinking is why we write instead of a fixed width .

Why the topic needs it: scipy.integrate.quad computes this area adaptively — but to know what "the answer" should be, you must know the area idea.


3. Slope and the derivative — how steep is the curve?

The parent's second derivation minimizes a function using . What is that fraction?

Figure — SciPy — overview of submodules

Reading : "" again means a tiny change. = tiny change in output; = tiny change in input. Their ratio is rise-over-run in the limit of a tiny run — exactly the slope.

Why the topic needs it: scipy.optimize.minimize walks downhill — it follows the slope down until the slope flattens. See Optimization — gradient descent.


4. The system — many equations at once

The parent solves and writes it as . Decode each letter.

For the parent's example:

How the shorthand unpacks: multiplying a matrix row by the unknown column means "multiply pairwise and add". Row 1 gives ; set equal to 's first entry . Row 2 gives . The two equations are back. See Linear algebra — solving Ax=b.

Why the topic needs it: scipy.linalg.solve finds this for you (via LU decomposition), and it is the flagship example of the whole parent note.


5. The "mostly-zero" matrix — why exists

The picture / the numbers: a grid has cells. Each 64-bit float takes 8 bytes, so a dense store needs bytes = 8 terabytes — the parent's exact warning. If only a few entries per row are nonzero, Sparse matrices shrinks this to gigabytes.


6. Frequencies and the FFT — one more submodule word

You don't need the full mathematics here — only to recognise the word when you meet scipy.fft in the submodule map.


7. Probability distribution — for


How these foundations feed the topic

Array grid of numbers

Function f of x

Matrix A x equals b

Area integral

Slope derivative

scipy integrate quad

scipy optimize minimize

scipy linalg solve

scipy sparse huge zeros

scipy fft frequencies

scipy stats distributions

SciPy toolbox

Read it upward: everything rests on the array; functions and matrices grow from it; area and slope grow from functions; and each SciPy submodule is a machine sitting on top of exactly one of these ideas.


Equipment checklist

Cover the right side and test yourself. If any answer surprises you, re-read that section before tackling the parent note.

What is an array, in one picture?
A grid of numbers in one memory block — a row (1-D) or rectangle (2-D) of boxes.
What does mean?
The output of rule/machine when fed the input ; drawn, it's a curve.
In Python, what does ** do?
Raises to a power — x**2 is squared, not multiplication.
Read every piece of .
Sum, from to , of height times tiny width — i.e. the area under the curve.
What is the trapezoid height for a strip?
The average of the two edge heights, .
What is a slope?
Rise over run — how much the output climbs per small step right.
What is the derivative ?
The slope of the curve at one exact point (steepness of the tangent line).
Why does slope mark a minimum?
The curve goes down then up; at the bottom it's momentarily flat, so its slope is zero.
Unpack into words.
= coefficient matrix, = unknown vector, = answers; it packs many linear equations into one line.
Solve .
.
Why use a sparse matrix for a giant mostly-zero system?
It stores only nonzeros; a dense float64 grid would need ~8 terabytes.
What does an FFT tell you about a signal?
Which repeating frequencies it is built from.
What does a probability distribution use that we also used for integration?
Area under a curve — area over a range gives the probability.

Recall Which SciPy tool sits on which foundation?

Area under a curve → integrate.quad. Slope/derivative → optimize.minimize. Matrix linalg.solve. Mostly-zero matrix → sparse. Frequencies → fft. Distributions → stats. Every one of them eats a NumPy array.