← Computational Mathematical Biology

NumPy

NumPy provides efficient numerical arrays and mathematical operations. It is the foundation of much scientific computing in Python.

Arrays

import numpy as np

x = np.array([1.0, 2.0, 3.0])
print(x.mean())

Vectorised calculations

t = np.linspace(0, 20, 201)
r = 0.2
N0 = 10
N = N0 * np.exp(r * t)

Vectorisation applies an operation to an entire array without writing a Python loop for each element.

Matrices

A = np.array([[0, 1], [1, 0]])
x = np.array([0.7, 0.3])
y = A @ x
Key idea. NumPy turns vectors, matrices and time grids into computational objects that closely match their mathematical notation.