pythonsympybinomial-cdf

Sympy Stats: ValueError: not an integer ​


I am trying to manipulate binomial distributions algebraically. Specifically, I would like to get the expected value and standard deviation of a random variable:

import sympy
import sympy.stats
from sympy import *

a = sympy.Symbol('a', integer=True)
W = sympy.stats.Binomial('W', a, sympy.S.Half, +1, -1) 
print (W)
print (sympify(a).is_integer)

sympy.stats.E(W)

which outputs

W
True

then throws ValueError: a is not an integer. I wonder what i am doing wrong here. ​


Solution

  • When I copy and paste your code into a current master I get

    Sum(Piecewise((2**(-_k)*2**(_k - a)*_k*binomial(a, _k), (_k >= 0) & (_k <= a)), (0, True)), (_k, 0, a))
    

    Perhaps you are using an older version of SymPy.