Python
import numpy as np

rng = np.random.default_rng(seed=42)
scores = rng.normal(loc=70, scale=10, size=1000).round(1)

print("First ten:", scores[:10])
print(f"Mean {scores.mean():.2f}, standard deviation {scores.std():.2f}")
print("Lowest and highest:", scores.min(), scores.max())
print("Scores above 85:", np.count_nonzero(scores > 85))

# Solve the equations 2x + y = 3 and x + 3y = 5
a = np.array([[2, 1], [1, 3]])
b = np.array([3, 5])
x = np.linalg.solve(a, b)
print("x and y:", x)
print("Check:", a @ x)

Press Run or Ctrl ↵ to execute main.py.
Type program input here while it runs.

Python

NumPy Online Compiler

import numpy as np works straight away: NumPy 2.5 is installed for Python 3.12, the default (2.4 if you pick Python 3.11 in Run settings), with pandas and openpyxl beside it. The editor opens with a script that summarizes 1,000 random scores and solves two equations.

Try it above

How Python runs here

Versions
Python 3.11, 3.12 (default), 3.13, 3.14, 3.15
Run
python3 -u main.py
Limits per run
256 MB memory, 15 s of CPU time on 2 cores, 2 MB of output
Time
Up to 10 minutes a run (30 on a paid plan); waits 2 minutes for input (5 on a paid plan)
Sandbox
Each run gets its own Linux sandbox with no network access. Text files your program writes next to your code open as new tabs.
Good to know
NumPy, pandas, Matplotlib and openpyxl installed.

What the starter script prints

default_rng(seed=42) gives the same numbers on every run, so pressing Run prints exactly this:

Terminal
$ python3 -u main.py
First ten: [73.  59.6 77.5 79.4 50.5 57.  71.3 66.8 69.8 61.5]
Mean 69.71, standard deviation 9.89
Lowest and highest: 33.5 101.8
Scores above 85: 62
x and y: [0.8 1.4]
Check: [3. 5.]

NumPy prints arrays without commas, and 73. is 73.0. np.linalg.solve() returned x = 0.8 and y = 1.4, and a @ x multiplies the matrix back to check the right-hand side.

Reading numbers into an array

input() waits for you to type in the terminal and returns text. Split it and give a dtype, and the line becomes an array you can compute with:

Python
import numpy as np

values = np.array(input("Numbers: ").split(), dtype=float)
print("Sorted:", np.sort(values))
print("Mean:", values.mean(), "std:", values.std().round(2))
print("Z-scores:", ((values - values.mean()) / values.std()).round(2))
Terminal
$ python3 -u main.py
Numbers: 12 7 30 5
Sorted: [ 5.  7. 12. 30.]
Mean: 13.5 std: 9.86
Z-scores: [-0.15 -0.66  1.67 -0.86]

Leave out dtype=float and you get an array of strings: sorting still works, alphabetically, but mean() fails with a TypeError. For many lines of input, read a count first and call input() that many times; sys.stdin.read() waits for an end of input that the terminal never sends.

Loading and saving data

Upload a CSV with the upload button and it sits next to main.py. np.loadtxt() reads plain numeric tables; np.genfromtxt() copes with missing values. Text files your script writes at the top level, such as np.savetxt("means.csv", ...), open as new tabs when the run ends:

Python
import numpy as np

data = np.loadtxt("data.csv", delimiter=",", skiprows=1)   # a CSV you uploaded, header row skipped
print(data.shape, data.mean(axis=0).round(2))
np.savetxt("means.csv", data.mean(axis=0, keepdims=True), delimiter=",", fmt="%.2f")

np.save() writes a binary .npy file, which the playground doesn’t open; save as text with savetxt() if you want to see the result.

What isn’t available here

  • SciPy, scikit-learn and statsmodels aren’t installed on the server runner, and runs have no network for pip. In Run settings, Run Python on: This browser runs your code with Pyodide, where imports such as scipy install themselves.
  • Charts and images. The playground shows text, so print arrays and summaries rather than plotting.
  • GPU arrays (CuPy) and NumPy builds with special BLAS options. It’s the standard NumPy wheel.

Errors you’ll see

  • “ValueError: operands could not be broadcast together with shapes (3,) (4,)” The arrays’ shapes don’t line up. Print a.shape and b.shape; often one needs reshape() or a new axis with a[:, None].
  • “ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()” An if or and got a whole array. Use a mask, np.where(), or .any() / .all().
  • “AttributeError: module 'numpy' has no attribute 'float'.” np.float, np.int and np.bool were removed. Use float, int and bool, or np.float64.
  • “ValueError: cannot reshape array of size 6 into shape (4,2)” The new shape must hold the same number of elements. Use -1 for one dimension: a.reshape(-1, 2).
  • “ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0 …” For a @ b, the columns of a must equal the rows of b. Transpose one with .T.

For a shape mismatch in a longer calculation, Fix with AI under the failed run points to the array with the wrong shape and proposes a change as a diff.

NumPy 2 in practice

  • Scalars show their type in reprs: print(values.mean()) prints 13.5, but print([values.mean()]) prints [np.float64(13.5)]. Convert with float() when you need plain numbers in a list or JSON.
  • Integer arrays are int64 and wrap around silently on overflow: np.array([2**62]) * 4 gives [0]. Use float64 or Python ints for very large values.
  • np.random.default_rng(seed) is the current way to make random numbers; the old np.random.seed() still works but shares one global state.
  • Prefer one array expression to a Python loop over the elements: the work then happens in NumPy’s compiled code, which matters with 15 seconds of CPU time per run.

Questions

Is NumPy installed, and which version?

Yes. NumPy 2.5 for Python 3.12 to 3.15, and 2.4 for Python 3.11, with pandas and openpyxl.

Can I use SciPy or scikit-learn?

Not on the server runner, which has no pip. Switch Run Python on to This browser in Run settings: Pyodide installs packages such as SciPy when you import them.

How do I read numbers from input into a NumPy array?

np.array(input().split(), dtype=float) turns a line like 12 7 30 5 into a float array. Type the numbers in the terminal while the program runs.

Can I load my own data?

Yes. Upload a CSV or text file and read it with np.loadtxt() or np.genfromtxt(). Text files your program writes open as new tabs.

Can I plot NumPy arrays?

No. The playground shows text output only, so print the values or summaries you need.