numpy.random.negative_binomial
- 
numpy.random.negative_binomial(n, p, size=None)
- 
Draw samples from a negative binomial distribution. Samples are drawn from a negative binomial distribution with specified parameters, nsuccesses andpprobability of success wherenis an integer > 0 andpis in the interval [0, 1].Parameters: - 
n : int or array_like of ints
- 
Parameter of the distribution, > 0. Floats are also accepted, but they will be truncated to integers. 
- 
p : float or array_like of floats
- 
Parameter of the distribution, >= 0 and <=1. 
- 
size : int or tuple of ints, optional
- 
Output shape. If the given shape is, e.g., (m, n, k), thenm * n * ksamples are drawn. If size isNone(default), a single value is returned ifnandpare both scalars. Otherwise,np.broadcast(n, p).sizesamples are drawn.
 Returns: - 
out : ndarray or scalar
- 
Drawn samples from the parameterized negative binomial distribution, where each sample is equal to N, the number of failures that occurred before a total of n successes was reached. 
 NotesThe probability density for the negative binomial distribution is where is the number of successes, is the probability of success, and is the number of trials. The negative binomial distribution gives the probability of N failures given n successes, with a success on the last trial. If one throws a die repeatedly until the third time a “1” appears, then the probability distribution of the number of non-“1”s that appear before the third “1” is a negative binomial distribution. References[1] Weisstein, Eric W. “Negative Binomial Distribution.” From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/NegativeBinomialDistribution.html [2] Wikipedia, “Negative binomial distribution”, https://en.wikipedia.org/wiki/Negative_binomial_distribution ExamplesDraw samples from the distribution: A real world example. A company drills wild-cat oil exploration wells, each with an estimated probability of success of 0.1. What is the probability of having one success for each successive well, that is what is the probability of a single success after drilling 5 wells, after 6 wells, etc.? >>> s = np.random.negative_binomial(1, 0.1, 100000) >>> for i in range(1, 11): ... probability = sum(s<i) / 100000. ... print i, "wells drilled, probability of one success =", probability 
- 
    © 2005–2019 NumPy Developers
Licensed under the 3-clause BSD License.
    https://docs.scipy.org/doc/numpy-1.16.1/reference/generated/numpy.random.negative_binomial.html