import numpy as np
N = 10000 MOD = 10 ** 10
comb = np.zeros((N+1,N+1),dtype=np.int64)
comb[:,0] = 1
%%time for n in range(1,N+1): comb[n, 1:n+1] = comb[n-1, :n] + comb[n-1, 1:n+1] comb[n] %= MOD
Wall time: 1.05 s
comb[:10, :10]
array([[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [ 1, 2, 1, 0, 0, 0, 0, 0, 0, 0], [ 1, 3, 3, 1, 0, 0, 0, 0, 0, 0], [ 1, 4, 6, 4, 1, 0, 0, 0, 0, 0], [ 1, 5, 10, 10, 5, 1, 0, 0, 0, 0], [ 1, 6, 15, 20, 15, 6, 1, 0, 0, 0], [ 1, 7, 21, 35, 35, 21, 7, 1, 0, 0], [ 1, 8, 28, 56, 70, 56, 28, 8, 1, 0], [ 1, 9, 36, 84, 126, 126, 84, 36, 9, 1]], dtype=int64)