Learn to write a NumPy tutorial¶

Image credit: Daniele Procida's DiĂĄtaxis framework, licensed under CC-BY-SA 4.0.
What youâll do¶
Guided by a template, youâll write a NumPy tutorial.
What youâll learn¶
Youâll be able to craft a tutorial that follows a standard format and reflects good teaching practice.
Youâll learn the three standard headings that open a NumPy tutorial â What youâll do, What youâll learn, and What youâll need â and some optional headings for the bottom â On your own, In practice, Further reading.
Youâll know what makes What youâll learn different from What youâll do.
Youâll be able to distinguish a tutorial from a how-to.
Youâll learn what not to put in a What youâll learn section.
What youâll need¶
This template.
A portrait of your intended reader.
Just as schools list prerequisites for higher-level courses, you can assume readers know some things (which you must list, as noted in the next bullet). Overexplaining bogs down the tutorial and obscures the main points.
But also put yourself in the readerâs place and consider what to explain along the way.
âWhat youâll needâ is a list of:
packages that must be present on the userâs machine before they begin. Donât include
numpy.what you assumed the reader knew in the bullet above. Donât say
Python;familiarity with Python iteratorsis fine.
Informality and enthusiasm. Imagine your reader not out in the audience but next to you.
Willingness to write incomplete sentences for the What youâll need bullets. They donât begin with the words âYouâll need.â
Not required are native English skills. Others can help.
After a horizontal rule, start your own headings¶
Your tutorial steps begin here, using headings of your choice. At the end of the tutorial youâll place another horizontal rule and return to standard headings.
Titles have verbs¶
In general, include a verb in the title; thus Learn to write a NumPy tutorial rather than âRules for NumPy tutorials.â Consider putting verbs in the headings as well.
Titles are lowercase¶
Capitalize the first word, and after that only words that are ordinarily capitalized (so not âTitles Are Lowercaseâ).
What to say in âWhat youâll learnâ¶
Avoid abstraction. âAboutâ is a tipoff: Rather than writing âYouâll learn about NumPy I/O,â write âYouâll learn how to read a comma-delimited text file into a NumPy array.â
Why are âWhat youâll doâ and âWhat youâll learnâ different?¶
What youâll do is typically one sentence listing an end product: âYouâll bake a cake.â This makes the endpoint clear. What youâll learn lists the payoffs, and there may be many: âYouâll learn to follow a recipe. Youâll get practice measuring ingredients. Youâll learn how to tell when a cake is ready to come out of the oven.â
Avoid asides¶
As explained by expert documentation writer Daniele Procida:
Donât explain anything the learner doesnât need to know in order to complete the tutorial.
Because tutorial steps are chosen to be clear and easy, they may fall short of
production-grade. Yes, you should share this, but not during the tutorial, which should be straightforward and assured. The In practice section is the place for details, exceptions, alternatives, and similar fine print.
Use plots and illustrations¶
Figures are a double win; they amplify your points and make the page inviting. Like English skills, artistic skills (or graphic-toolset skills) arenât required. Even if you only scan a hand illustration, somebody can polish it.
An illustration below the title, even if itâs only decorative, makes your page distinctive.
Use real datasets when possible¶
Readers are likelier to be engaged by a real use case. Be sure you have rights to the data.
Tutorials and how-toâs â similar but different¶
Tutorial readers are out-of-towners who want a feel for the place. Pick any single destination and explain sights along the way.
Unlike how-to readers, who know what they need, tutorial readers donât know what it is they donât know. So while tutorials need headings like What youâll do and What youâll learn, these headings would never appear in a how-to.
Make use of the Google doc style guide¶
NumPy docs follow the Google developer documentation style guide. In addition to providing answers to recurring questions (âcrossreferenceâ or âcross-referenceâ?) the guide is filled with suggestions that will strengthen your doc writing.
The notebook must be fully executable¶
Run all cells should execute all cells to the bottom of the file. If youâre demonstrating a bad expression and want to show the traceback, comment
the expression and put the traceback in a text cell.
(Note that triple backquotes wonât be enough for a traceback that contains <text inside angle brackets>,
the angle brackets must be replaced by < and > as shown in the text cell markdown below.)
# 100/0
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-10-bbe761e74a70> in <module>
----> 1 100/0
ZeroDivisionError: division by zero
On your own¶
Close the tutorial section with a horizontal rule. Youâre free to take any direction now, but here are three suggested sections.
In an optional On your own section, you can offer an assignment for readers to exercise their new skills. If itâs a question with an answer, provide it â perhaps in a footnote to keep it from being a spoiler.
In practiceâŠÂ¶
The fine print that you avoided can go in this section.
Donât just say itâs usually done another way; explain why.
Further reading¶
Ideally, rather than giving bare links, Further reading describes the references: The Documentation System is the inspiration for this tutorial, and describes three other kinds of documentation.
The Google guide is long; thereâs also a summary.
NumPyâs website includes a documentation how-to.