Repository navigation
Create an example driven NumPy lesson - #341
Draft
wmvanvliet wants to merge 25 commits into
Draft
wmvanvliet wants to merge 25 commits into
wmvanvliet wants to merge 25 commits into
Conversation
wmvanvliet
marked this pull request as draft
July 5, 2026 08:37
Member
|
@wmvanvliet this is good! Do you think it should be merged before the next run? |
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 |
…comp into example-driven
…comp into example-driven
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.polyfitin 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.