from scipy.special import betaln
from scipy.misc import logsumexp
import numpy as np

def binomln(n, k):
    return -betaln(1 + n - k, 1 + k) - np.log(n + 1)
for n in range(2, 1000, 10):
    m = 2.2 * n / np.log(n)
a = np.arange(1, n + 1)[(np.newaxis), :]
b = np.arange(n + 1)[:, (np.newaxis)]
v = binomln(n, a) + binomln(n - a, b) + m * binomln(a + b, a) - m * (a + b
    ) * np.log(2)
term = np.exp(logsumexp(v))
print(term)
How to compute an expensive high precision sum in python?