This code should output 2/6 but I just get 0
from sympy.stats import Die, P, Normal
n = 6
X = Die('X', n) # Six sided Die
P(X == 1) + P(X == 5)
Even when I just try to calculate the probability of the die landing on a specific number like P(X==1), it outputs 0!
Die doesn't implement equals in the way you are expecting it to. If you just write X == 1 the result is False. However, if you write something like X > 3 you do not get True or False, you get an expression (meaning P can hope to return something from it).
When you write
P(X == 1)
That is identical to writing
P(False)
which is meaningless for a die. If you want the probabilities of each face, you can use density:
from sympy.stats import Die, P, Normal, density
n = 6
X = Die('X', n) # Six sided Die
density(X)[1] + density(X)[5] # 1/3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With