# Educational example from Sarovi journal. Python 3; no extra dependencies.
def matvec(matrix, vector):
    if any(len(row) != len(vector) for row in matrix):
        raise ValueError("incompatible dimensions")
    return [sum(a*b for a, b in zip(row, vector)) for row in matrix]

assert matvec([[2, 1], [1, 3]], [4, 5]) == [13, 19]
assert matvec([[1, 0], [0, 1]], [4, 5]) == [4, 5]
print("all checks passed")
