NumPy playground

NumPy Online: Run NumPy Code in Your Browser

A NumPy playground with nothing to install: open the editor, import numpy as np and run. NumPy 2, pandas, SciPy and Matplotlib are already there. Try the examples below, then change them.

Arrays, statistics and filtering

A 2D array holds four students' scores in three tests. axis=1 works per row and axis=0 per column; a condition such as scores > 80 selects matching values.

arrays.py
Run this code →
arrays.py
import numpy as np

scores = np.array([[72, 85, 90], [64, 78, 88], [95, 91, 84], [58, 66, 71]])

print("Shape:", scores.shape)
print("Mean per student:", scores.mean(axis=1).round(1))
print("Best per test:", scores.max(axis=0))
print("Above 80:", scores[scores > 80])
print("Normalized (0-1):")
print(((scores - scores.min()) / (scores.max() - scores.min())).round(2))

Solve a system of linear equations

np.linalg.solve finds x, y and z in one call; @ multiplies matrices to check the answer, and det and inv give the determinant and inverse.

linear_algebra.py
Run this code →
linear_algebra.py
import numpy as np

# Solve 2x + y - z = 8, -3x - y + 2z = -11, -2x + y + 2z = -3
A = np.array([[2, 1, -1], [-3, -1, 2], [-2, 1, 2]])
b = np.array([8, -11, -3])

x = np.linalg.solve(A, b)
print("Solution x, y, z:", x)
print("Check A @ x == b:", np.allclose(A @ x, b))
print("Determinant:", round(np.linalg.det(A), 3))
print("Inverse:")
print(np.linalg.inv(A).round(3))

Random numbers without loops

rng.integers rolls 10,000 pairs of dice in one array, and np.unique counts each total: vectorized code instead of a Python loop.

dice.py
Run this code →
dice.py
import numpy as np

rng = np.random.default_rng(42)

# Simulate 10,000 rolls of two dice, without a loop
rolls = rng.integers(1, 7, size=(10_000, 2)).sum(axis=1)
values, counts = np.unique(rolls, return_counts=True)
for value, count in zip(values, counts):
    print(f"{value:2d} {'#' * (count // 50)} {count / len(rolls):.3f}")

print("Most common total:", values[counts.argmax()])

Broadcasting

A (2, 3) price table times a (3,) tax array: NumPy stretches the smaller array across the rows, so there is no loop.

broadcasting.py
Run this code →
broadcasting.py
import numpy as np

prices = np.array([[10.0, 12.5, 8.0],     # store A
                   [11.0, 12.0, 7.5]])    # store B
tax = np.array([0.08, 0.10, 0.05])         # one rate per product

with_tax = prices * (1 + tax)              # (2, 3) * (3,) -> (2, 3)
print(with_tax.round(2))
print("Cheapest store per product:", np.array(["A", "B"])[with_tax.argmin(axis=0)])

Frequently asked questions

Can I run NumPy online?

Yes. NumPy is installed in the online Python editor. Write import numpy as np and run your code; nothing to install.

Which NumPy version is it?

NumPy 2, together with pandas, SciPy and Matplotlib.

Is this a NumPy playground?

Yes. Each example opens in an editor where you can change the code and run it again as many times as you like.

Can I plot NumPy arrays?

Yes, use the online Matplotlib editor, which shows the charts in the page.

Can I use my own data?

Upload a CSV or text file to your workspace and read it with np.loadtxt, np.genfromtxt or pandas.