Run NumPy Online – Free NumPy Online Compiler

Run NumPy arrays and matrix online in your browser with our free online NumPy compiler. No installation or signup required - Try It Now.

Try This NumPy Example

import numpy as np

# Create arrays
arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

print("Array:", arr)
print("Matrix:\n", matrix)
print("\nArray Statistics:")
print(f"  Mean:    {arr.mean():.2f}")
print(f"  Std Dev: {arr.std():.2f}")
print(f"  Sum:     {arr.sum()}")

print("\nMatrix Operations:")
print(f"  Shape:     {matrix.shape}")
print(f"  Transpose:\n{matrix.T}")

# Linear algebra
a = np.array([[2, 1], [5, 3]])
b = np.array([8, 13])
solution = np.linalg.solve(a, b)
print(f"\nSolving linear system Ax = b:")
print(f"  x = {solution}")
Open in full editor →Loads instantly in your browser. No install.

What You Can Do With NumPy Online

Array & Matrix Operations

Create N-dimensional arrays, reshape matrices, compute dot products, and perform element-wise operations — all with pure NumPy syntax.

Linear Algebra & Statistics

Run np.linalg.solve(), np.dot(), np.mean(), np.std(), and more. Perfect for data science assignments, ML prep, and numerical computing.

Zero Setup, Full Library

NumPy, pandas, and Matplotlib are pre-installed in the browser runtime. Open the editor and import numpy as np immediately.

How to Run NumPy Arrays Online

Our free online NumPy compiler provides a full scientific computing environment directly in your browser. Whether you are practicing for a data science interview or calculating complex algorithms, here is how to start:

  1. Import NumPy: Begin your script with the standard import convention: import numpy as np.
  2. Create Arrays: Replace slow Python lists with fast, typed multidimensional arrays using np.array([1, 2, 3]), or generate them programmatically with np.zeros((3, 3)), np.ones(10), np.arange(0, 100, 2), and np.linspace(0, 1, 50).
  3. Index and Slice: Use arr[2:7], matrix[:, 0] for the first column, or boolean masks like arr[arr > 0] to pull out exactly the data you want — no copies until you ask for one.
  4. Do Math, the Vectorised Way: Add, multiply, raise to powers, take sines and exponentials directly on whole arrays: 2 * arr + 1, np.exp(arr), a @ b for matrix multiplication.
  5. Aggregate: Collapse arrays with arr.sum(), arr.mean(), arr.std(), arr.min(), arr.max() — and use axis=0 or axis=1 to reduce along rows or columns of a matrix.
  6. Reshape Freely: arr.reshape(4, 5), arr.flatten(), arr.T for transpose, or np.stack / np.concatenate to glue arrays together along any axis.
  7. Save and Load: Persist arrays with np.save("data.npy", arr) and read them back with np.load("data.npy"), or use np.savetxt / np.loadtxt for plain CSV interchange.

To explore all available mathematical functions, random number generators, and Fourier transforms, visit the official NumPy documentation.

NumPy vs Python Lists — A Speed Showdown

The first time you run a vectorised NumPy expression next to its list-comprehension twin, the gap is hard to believe. NumPy is not faster because it cheats — it is faster because it stops doing the slow things Python does by default.

A Python list of a million integers is a million boxed PyObjects scattered across the heap, each carrying a type tag, a refcount, and a pointer dance to reach its value. A NumPy array is one flat, contiguous buffer of fixed-width C numbers. That single layout choice unlocks three multipliers stacked on top of each other:

  • No Python interpreter in the hot loop. Operations like arr * 2 dispatch into a tight C loop — one bytecode instruction on the Python side, millions of native multiplications on the C side.
  • SIMD-friendly memory. Because the bytes sit next to each other, the CPU can stream cache lines and use vector instructions (SSE/AVX/NEON) to multiply 4 or 8 numbers per cycle.
  • BLAS & LAPACK. Linear algebra (@, np.dot, np.linalg.solve) hands off to libraries that have been hand-tuned by humans for decades.

Run the snippet below in the editor and watch the timings yourself — the vectorised version is often 50-100x faster on numerical workloads, and the gap widens as arrays grow.

import numpy as np
import time

# Task: square a million numbers

# Pure Python — looped, boxed, slow
data = list(range(1_000_000))
t0 = time.time()
squared = [x * x for x in data]
print(f"List comprehension: {time.time() - t0:.4f}s")

# NumPy — contiguous memory, vectorised C loop
arr = np.arange(1_000_000)
t0 = time.time()
squared = arr * arr            # the whole array, in one shot
print(f"NumPy vectorised:   {time.time() - t0:.4f}s")
# Often 50-100x faster on numerical workloads

Broadcasting — The Magic Rule You Need to Master

If there is one NumPy concept worth tattooing on the back of your hand, it is broadcasting. Broadcasting is the rule that lets a (3,) array combine cleanly with a (3, 3) matrix, or a single scalar mix with a 4D tensor, without you ever writing a loop or calling tile.

The rule, in plain English: two arrays are compatible if their shapes match from the right, with size 1 or missing dimensions allowed. NumPy compares the shapes axis by axis, starting from the trailing dimension. If a pair matches, great. If one of them is 1, NumPy stretches it. If one of them is missing, NumPy prepends a 1 and stretches that. Anything else is an error.

Three concrete cases cover almost everything you will meet:

import numpy as np

# 1) 1D array + scalar — scalar stretches to match
prices = np.array([10.0, 20.0, 30.0])
with_tax = prices * 1.2          # -> [12., 24., 36.]

# 2) 2D matrix + 1D row — row broadcasts down every row
matrix = np.array([[1, 2, 3],
                   [4, 5, 6],
                   [7, 8, 9]])
row_bias = np.array([10, 20, 30])  # shape (3,)
print(matrix + row_bias)
# [[11 22 33]
#  [14 25 36]
#  [17 28 39]]

# 3) 2D matrix + 1D column — reshape to (3, 1) so it broadcasts across
col_bias = np.array([100, 200, 300]).reshape(3, 1)
print(matrix + col_bias)
# [[101 102 103]
#  [204 205 206]
#  [307 308 309]]

Notice case 3: a 1D array of shape (3,) broadcasts across the rows by default. To broadcast down the columns instead, you reshape it to (3, 1) — a shape with an explicit trailing 1 that the matrix can stretch through. This is the trick behind centring features, normalising images per channel, and most attention-mechanism shapes you will ever write.

Once broadcasting clicks, you stop writing for-loops. You start writing arithmetic.

10 NumPy One-Liners Every Data Scientist Should Know

These are the snippets you will reach for again and again. Drop any of them straight into the editor — they all run in the browser without an install.

np.linspace

x = np.linspace(0, 2 * np.pi, 100)

Generate exactly 100 evenly spaced points between two endpoints — perfect for plotting smooth curves.

np.where

labels = np.where(scores >= 50, "pass", "fail")

Vectorised ternary: pick from one of two arrays based on a boolean condition, element by element.

np.argmax / np.argmin

best_idx = np.argmax(predictions, axis=1)

Return the index of the largest (or smallest) value along an axis — the standard way to read off classifier predictions.

np.unique with return_counts

values, counts = np.unique(labels, return_counts=True)

Get every distinct value and how often it appears — a one-line histogram for categorical data.

np.percentile

p25, p50, p75 = np.percentile(data, [25, 50, 75])

Compute multiple quantiles in a single pass — handy for box plots and outlier detection.

np.clip

safe = np.clip(arr, 0, 1)

Squash every value into [min, max]. Great for keeping probabilities in range or capping outliers.

np.einsum

result = np.einsum("ij,jk->ik", A, B)

Express any tensor contraction — matrix multiply, batched dot product, trace — in one compact, often faster line.

np.allclose

np.allclose(predicted, expected, atol=1e-6)

Compare two float arrays with tolerance — the right way to write numerical tests where == fails on rounding.

Boolean fancy indexing

positives = arr[arr > 0]

Select elements directly with a boolean mask — cleaner than a Python filter() and orders of magnitude faster.

np.meshgrid

X, Y = np.meshgrid(np.linspace(-1, 1, 50), np.linspace(-1, 1, 50))

Build the coordinate grids you need to evaluate a function over a 2D plane — the foundation of every contour plot.

From NumPy to Deep Learning

Every modern deep-learning framework is, at heart, NumPy with a few extra superpowers bolted on. PyTorch tensors mirror NumPy arrays almost line for line — torch.zeros, torch.matmul, tensor.reshape, broadcasting rules included — but add autograd and a GPU backend. JAX goes further: it is literally a NumPy clone (jax.numpy) wrapped in jit, grad, vmap, and an XLA compiler. TensorFlow’s eager mode and CuPy’s CUDA arrays follow the same playbook.

The reason this works is the Python Array API standard, the cross-library spec that NumPy 2.0 fully adopted. It pins down the names, shapes, and semantics of array operations so library authors can write code once and have it run on NumPy, CuPy, JAX, PyTorch, or any future array backend without rewrites.

The practical takeaway: the time you spend mastering reshape, broadcasting, fancy indexing, and einsum here is not a stepping stone you throw away when you move to a GPU framework. It is the framework. Learn NumPy in the browser today and you are 80% of the way to PyTorch and JAX tomorrow.

Frequently Asked Questions

Can I run NumPy online without installing Python?

Yes. PythonHere runs Python in your browser via WebAssembly (Pyodide). NumPy is pre-loaded — just import numpy as np and run.

Does it support matrix operations and linear algebra?

Yes. All core NumPy functionality works: array creation, slicing, reshaping, np.linalg, np.fft, random number generation, and more.

Is it free?

100% free, forever. No account required, no time limit, no credit card.

Can I use pandas alongside NumPy?

Yes. Both pandas and NumPy are available simultaneously. Use them together as you would in a local environment.

Which NumPy version runs in the browser?

PythonHere ships the NumPy build that the current Pyodide release bundles — at the time of writing this is NumPy 1.26+ from the Pyodide 0.29.x distribution. You can confirm the exact version any time by running np.__version__ in the editor.

Can I use NumPy 2.x features here?

NumPy 2.0 introduced a cleaner public API, the new variable-length StringDType, the numpy.strings namespace, improved type promotion (NEP 50), and full Array API standard support. As Pyodide tracks the latest stable NumPy, those features land in the browser shortly after each release. If a 2.x feature is missing, run np.__version__ to check what is currently shipped.

Why is NumPy faster than Python lists?

NumPy stores numbers in a single contiguous block of memory using fixed-width C types — not as boxed Python objects scattered across the heap. Operations are then dispatched to vectorised C loops (and BLAS/LAPACK for linear algebra) instead of Python-level for-loops, which lets the CPU stream data through SIMD-friendly hot paths. The result is often 50-100x faster than the equivalent list comprehension on numerical workloads.

Does this support np.linalg, np.fft, and np.random?

Yes. The full numerical stack is available: np.linalg for solve / inv / eig / svd / qr, np.fft for forward and inverse Fourier transforms (now with float32 and longdouble support in 2.x), and np.random with the modern Generator API (default_rng()) plus the legacy RandomState.

Can I run GPU-accelerated NumPy in the browser?

Not via Pyodide — WebAssembly currently has no direct path to CUDA or Metal, so PythonHere runs on the CPU only. If you need GPU acceleration, the closest drop-in replacements outside the browser are CuPy (CUDA, NumPy-compatible API) and JAX (XLA, with jit and autodiff). Both follow the Array API standard, so code written against NumPy here ports over with minimal changes.

How do I import data — CSV, .npy files?

For CSVs, use np.loadtxt("data.csv", delimiter=",") or, for messy real-world files, np.genfromtxt with skip_header / missing_values. For NumPy native formats, np.load("array.npy") reads .npy and np.savez_compressed writes .npz archives. You can drag-and-drop files into the editor sidebar to make them visible to the runtime.

Can I use NumPy with Matplotlib in the same browser session?

Yes. Build your arrays with NumPy, hand them to Matplotlib via plt.plot(x, y) or plt.imshow(matrix), and the chart renders directly in the output panel — no separate viewer, no save-to-disk roundtrip.

Explore More Python Libraries Online

Run NumPy in Your Browser Right Now

Free forever. No install. No signup.

Open the NumPy Editor →