Skip to content

Create an example driven NumPy lesson - #341

Draft
wmvanvliet wants to merge 25 commits into
AaltoSciComp:masterfrom
wmvanvliet:example-driven
Draft

wmvanvliet wants to merge 25 commits into
AaltoSciComp:masterfrom
wmvanvliet:example-driven

Conversation

@wmvanvliet

@wmvanvliet wmvanvliet commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

This is an experiment in how a NumPy lesson could look if it were framed in the context of real scientific data, exploring a real scientific question.

The rendered version of this lesson can be found here: https://users.aalto.fi/~vanvlm1/python-for-scicomp/html/numpy-stars.html

This version uses the Gaia survey of the stars and uses its parallax values to compute distances to several known stars. Then it poses the question of an intriguing cluster of stars known as the Large Magallanic Cloud. It is too far away for Gaia to measure its parallax. How far away is it? In the final exercise, the students will discover it is very far... too far to be in our galaxy. Along the way, the lesson demonstrates the basics of NumPy and how it can be used to crunch the numbers on over a million stars in a few milliseconds.

Because the lesson works on real data, the students must download a 42.3MB data package that is a bit too large to be placed inside the repo. Especially if we chose to change more lessons to use real data and the data package grows.

This is a first attempt at framing one of our lessons like this. It probably needs tweaking in terms on length and difficulty. What I'm most unsure about is the linear algebra section where we fit a polynomial function. Doing it manually nicely shows off how to build arrays, matrix multiplication, transposition and inversion, and generally how a formula from Wikipedia translates into a line of NumPy code. The downside is that it exposes the students to linear algebra, i.e. somewhat complicated math, which may discourage some? Alternatively, the polynomial could be fitted with numpy.polyfit in a single line, skipping the math, but also skipping the demonstration on how to do linear algebra with NumPy.

Because this lesson works with real data, the results beg to be visualized. However, data visualization is not officially part of this lesson. It is currently presented as "just take this bit of code at face value, we will explain more about it in the data visualization lesson". Not optimal. But then again, not having any visualizations would also be a shame.

@wmvanvliet
wmvanvliet marked this pull request as draft July 5, 2026 08:37
@eglerean

Copy link
Copy Markdown
Member

@wmvanvliet this is good! Do you think it should be merged before the next run?

@wmvanvliet

Copy link
Copy Markdown
Contributor Author

That is a good question. I would really love to test-drive this lesson during this run. But it is kind of a big change, and numpy is an important lesson (which is why I overhauled it first), so would like to know if everyone is on board with trying this.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants