linhares
linhares

Reputation: 524

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. ​

Upvotes: 0

Views: 277

Answers (1)

smichr
smichr

Reputation: 19135

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.

Upvotes: 1

Related Questions