The NumPy workbench

Pyodide, preloaded np, files, Run, Reset, and privacy.

The NumPy app is a Python editor that runs in WebAssembly (Pyodide). When the status line says NumPy is ready, np already exists.

You do not write import numpy as np unless you want to. It does not hurt if you do.

Goal

Know how Run, files, Reset, and downloads work before you fight a FileNotFoundError.

Run code

Paste into the editor and press Ctrl+Enter (Windows/Linux) or Cmd+Enter (macOS). The console below the editor is stdout. Use print.

print("numpy", np.__version__)
print(np.array([10.5, 22.0, 31.0]))

You should see a version string and a 3-element array.

Files live in /uploads

Click Add files and choose a CSV or .txt file. After that:

import os

print(os.listdir("/uploads"))

Readable paths:

  • units.csv
  • /uploads/units.csv

If a name is missing from that listing, attach it before you run loadtxt.

Drop a .py file on the editor to open it as code. Add files is for data.

Writes become download chips

import os

out = np.arange(1, 4)
np.savetxt("demo.csv", out, delimiter=",", fmt="%.0f")
print("wrote demo.csv")
print(os.listdir("/uploads"))

After Run, click on the file chip. The workbench may also start a download. Nothing is uploaded to Swiftener’s servers.

Reset, autosave, snippets

  • Code autosaves in this browser.
  • Reset restores the starter snippet — it does not delete /uploads.
  • Snippets insert short recipes. This course’s blocks are longer on purpose.

Privacy

Python runs in this tab. Uploads live in IndexedDB on this device. Lesson pages on tutorials.swiftener.com are public HTML; they never see your arrays.

Pitfall

There is no matplotlib and no pandas in this app. Do not paste plotting or DataFrame examples from other sites. Print arrays instead.