Statistics: combinations in Python

前端 未结 18 1587
南旧
南旧 2020-11-27 10:14

I need to compute combinatorials (nCr) in Python but cannot find the function to do that in math, numpy or stat libraries. Something

18条回答
  •  悲哀的现实
    2020-11-27 10:55

    Using only standard library distributed with Python:

    import itertools
    
    def nCk(n, k):
        return len(list(itertools.combinations(range(n), k)))
    

提交回复
热议问题