Open In App

sympy.stats.NegativeBinomial() in Python

Last Updated : 08 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

With the help of sympy.stats.NegativeBinomial() method, we can get the random variable representing the negative binomial distribution.

Syntax : sympy.stats.NegativeBinomial(name, r, p)
Return : Return the random variable.

Example #1 :
In this example we can see that by using sympy.stats.NegativeBinomial() method, we are able to get the negative binomial distribution by using this method.




# Import sympy and Negativebinomial
from sympy.stats import NegativeBinomial, density, E, variance
from sympy import Symbol, S
  
r = 5
p = S.One / 5
  
# Using sympy.stats.NegativeBinomial() method
X = NegativeBinomial("x", r, p)
gfg = density(X)(0.5)
  
print(gfg)


Output :

0.360633043411166

Example #2 :




# Import sympy and Negativebinomial
from sympy.stats import NegativeBinomial, density, E, variance
from sympy import Symbol, S
  
r = 4
p = 0.6
z = Symbol("z")
  
# Using sympy.stats.NegativeBinomial() method
X = NegativeBinomial("x", r, p)
gfg = density(X)(z)
  
print(gfg)


Output :

0.0256*0.6**z*binomial(z + 3, z)


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads