def do_integral_weighted(N):
    res = np.zeros(N)
err = np.zeros(N)
for n in range(1, N):
    res[n], err[n] = integ.quad(g, 0, 1, weight='sin', wvar=n * np.pi)
return res, err
cw, errw = do_integral_weighted(500)
Sw = np.cumsum(cw[1:] ** 2)
Writing an infinite sum (of a function that has an integral) in Python