NumPy Ecosystem Map
Run the NumPy Ecosystem Map MicroSim Fullscreen
Edit in the p5.js Editor
About This MicroSim
NumPy sits in the middle of the Python data science tools. This map puts the NumPy array in the center and seven libraries around it. Two kinds of link are drawn.
- Built on NumPy (solid line): NumPy is a required dependency and the library computes with arrays inside. These are pandas, SciPy, scikit-learn and Matplotlib.
- Works with NumPy (dashed line): the library has its own engine or tensor type, and it accepts arrays or converts to and from them. These are Plotly, PyTorch and TensorFlow.
An arrowhead at the library means arrays go in. A second arrowhead at NumPy means results come back as arrays. The two charting libraries have one arrowhead, because a picture comes out, not data.
Selecting a library shows what it is for, how it uses NumPy, two lines of code that move data in each direction, and one thing worth remembering. For example, torch.from_numpy(arr) shares memory with the array on the CPU, so a change to one shows up in the other, and scikit-learn needs X to be 2-D, which is why X.reshape(-1, 1) appears so often.
Not included: the animation of data moving along the spokes, from the original specification. Memory sharing is stated only where the library's documentation is explicit about it.
How to Use
- Start with NumPy selected and read why it is in the middle.
- Click a library, or press Next and Previous, and read its panel. Say the two code lines out loud as array in and array out.
- Compare a solid link with a dashed link. Use the menu to show only one kind at a time.
- Find the libraries with one arrowhead and explain why nothing comes back to NumPy.
- For each library, name one place earlier in the course where you have already used it with an array.
Iframe Embed Code
You can add this MicroSim to any web page by adding this to your HTML:
1 2 3 4 | |
Lesson Plan
Grade Level
High School (11-12) and College Freshman
Duration
10-15 minutes
Prerequisites
Creating NumPy arrays, and some experience with at least one of pandas, Matplotlib or scikit-learn.
Bloom's Taxonomy Level
Understand (L2)
Learning Objective
Students will be able to describe how the main Python data science libraries depend on or exchange data with NumPy arrays, and give the call that converts between an array and each library's own data type.
Activities
- Sort (4 min): Before using the menu, students sort the seven libraries into built on NumPy and works with NumPy, then check with the filter.
- Read and record (6 min): For each library students copy the two code lines into a table with the columns library, array in, and array out.
- Trace a workflow (4 min): Students trace one path through the map for a small project: load a table with pandas, convert to an array, fit a scikit-learn model, and plot the predictions.
Assessment
Students write the line of code that turns a DataFrame into a NumPy array, the line that turns an array into a PyTorch tensor, and one sentence explaining why a single well-understood array type makes it possible to use these libraries together.
References
- Wikipedia. NumPy.
- pandas documentation. pandas.DataFrame.to_numpy.
- PyTorch documentation. torch.from_numpy.