def compute_inertial(points, weights, clusters, centroids) -> float:
    """ Compute the inertia (k-means loss, i.e. weighted sum of squared differences) """
    assert len(points) == len(weights) == len(clusters)
    assert all(0 <= k < len(centroids) for k in clusters)
    return sum(
        w * (x - centroids[k]) ** 2
        for x, w, k in zip(points, weights, clusters)
    )
 Compute the inertia (k-means loss, i.e. weighted sum of squared differences) 
deps/kmeans1d/tests/test_kmeans1d.py