This is one of the 100 recipes of the IPython Cookbook, the definitive guide to high-performance scientific computing and data science in Python.
n = 100000
%timeit sum([1. / i**2 for i in range(1, n)])
%%timeit s = 0.
for i in range(1, n):
s += 1. / i**2
import numpy as np
%timeit np.sum(1. / np.arange(1., n) ** 2)
You'll find all the explanations, figures, references, and much more in the book (to be released later this summer).
IPython Cookbook, by Cyrille Rossant, Packt Publishing, 2014 (500 pages).