Gap statistic method, in Python