[Python] Difference in output of sympy.binomial vs scipy.special.comb

Discussão em 'Python' iniciado por Stack, Março 6, 2025.

  1. Stack

    Stack Membro Participativo

    Why does the following code that calls comb produce the wrong output?

    from scipy.special import comb
    from sympy import binomial


    def coup(n=100, m=10):
    expectation = 0
    for j in range(1, n + 1):
    coeff = ((-1)**(j-1)) * comb(n, j)
    denominator = 1 - (comb(n - j, m) / comb(n, m))
    expectation += coeff / denominator

    print(expectation)

    # output: 1764921496446.9807
    # correct output when using binomial: 49.9445660566641

    Continue reading...

Compartilhe esta Página