1.4.9 · D3Python & Scientific Computing

Worked examples — Jupyter notebooks workflow

3,108 words14 min readBack to topic

Before anything: one word we will use on every line.


The scenario matrix

Every confusing thing Jupyter does is one of these case-classes. The examples below hit every row.

# Case class What varies Hit by
A Top-to-bottom order cells run 1,2,3 as written Ex 1
B Out-of-order execution a later cell runs before an earlier one Ex 2
C Redefinition / shadowing same name written twice Ex 3
D Degenerate: name never defined reading a name with no arrow Ex 4
E Reset: kernel restart namespace wiped to empty Ex 5
F Mutation vs re-assignment object changed in place vs replaced Ex 6
G Deletion: del removes an arrow a name is explicitly deleted Ex 7
H The "works-for-me" trap saved outputs vs live namespace Ex 8
I Real-world word problem a real analysis, predict R² Ex 9
J Exam-style twist predict every In [n] from a scramble Ex 10

A quick vocabulary note so the taxonomy stays clean: throughout this page "limiting behaviour" means only the edge/extreme end of a spectrum (an empty namespace, a zero input) — we reserve it for Case E's restart-to-empty and Case D's empty-slot read. It is never a case name.



Recall

Case A — in an honest run, what pattern do the In [n] numbers show? ::: They strictly increase (1,2,3…) — the sign nobody ran cells out of order. Case B — smaller In number below a larger one means what? ::: The notebook was run out of order (a reproducibility bomb). Case C — after n=3; n=n+7; n=n*2, what is n? ::: 20 — each cell reads the current arrow then overwrites it. Case D — NameError blames which name when several are missing? ::: The first undefined name Python meets, left-to-right. Case E — after Restart Kernel, what does the namespace contain? ::: Nothing — it is emptied to and the counter resets to In [1]. Case F — does b = a copy the list? ::: No; both names point to the same object, so mutating through a shows up in b. Case G — what does del temp remove, the value or the arrow? ::: The arrow (the name); reading temp afterwards raises NameError. Case H — saved outputs are a recipe or a photograph? ::: A photograph of the last run — not a reproducible recipe. Always Restart & Run All before sharing. Case I — with a perfect noiseless linear fit, what is ? ::: Exactly 1.0, because RSS = 0. Case J — how do you recover true run order? ::: Sort cells by ascending In [n] counter.

Back to the parent: Jupyter notebooks workflow · prerequisite 1.4.08-Virtual-environments · next steps 1.6.01-Matplotlib-basics.