comb
float64
, inf
.
exact=True
, Python int
, ( , ).
, np.log2
int
, Python math.log2
.
:
math.log2(scipy.misc.comb(5000, 2000, exact=True))
, n k, n!k / k!
, ? ∏(i=1...k)((n+1-i)/i)
, .
, , , * (n-i)
/ (k-i)
.
, , . , Python 4000 , C 4000 , , , , . :
In [1327]: n, k = 5000, 2000
In [1328]: %timeit math.log2(scipy.misc.comb(5000, 2000, exact=True))
100 loops, best of 3: 1.6 ms per loop
In [1329]: %timeit np.log2(np.arange(n-k+1, n+1)).sum() - np.log2(np.arange(1, k+1)).sum()
10000 loops, best of 3: 91.1 µs per loop
, , ... , , , . 2000 8- 608- . 100000, 20000, 20000 8- 9K . 1000000, 200000, 200000 8- 720K.
, . , listcomp genxpr, 5000, 100000 1000000 Python-float-24MB , 720K ? , , , , :
r = sum(math.log2(n-i) - math.log2(k-i) for i in range(n-k))
, scipy
, , ( Python). ( Python 2, ... xrange
range
.)
, NumPy ( , ) ( , )?