counting combinations and permutations efficiently

后端 未结 13 1963
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 12:38

I have some code to count permutations and combinations, and I\'m trying to make it work better for large numbers.

I\'ve found a better algorithm for permutations th

13条回答
  •  眼角桃花
    2020-12-02 13:17

    There's a function for this in scipy which hasn't been mentioned yet: scipy.special.comb. It seems efficient based on some quick timing results for your doctest (~0.004 seconds for comb(100000, 1000, 1) == comb(100000, 99000, 1)).

    [While this specific question seems to be about algorithms the question is there a math ncr function in python is marked as a duplicate of this...]

提交回复
热议问题