Matrix and Vector Operations

May 30, 2026 | 5 min read

Matrix Multiplication

def matmul(a: list[list[float]], b: list[list[float]]) -> list[list[float]]:
    n = len(a)
    m = len(b[0])
    p = len(b)
    result = [[0.0] * m for _ in range(n)]
    for i in range(n):
        for j in range(m):
            total = 0.0
            for k in range(p):
                total += a[i][k] * b[k][j]
            result[i][j] = total
    return result

Vector Dot Product

def dot(a: list[float], b: list[float]) -> float:
    total = 0.0
    for i in range(len(a)):
        total += a[i] * b[i]
    return total

When to Use NumPy

For large matrices (1000x1000+), NumPy's BLAS-backed operations will outperform compiled Python. Use Pyvorin for small-to-medium matrices where NumPy is overkill.