bundles / numpy latest / numpy / random / RandomState / negative_binomial
cython_function_or_method
numpy.random:RandomState.negative_binomial
Signature
def negative_binomial ( n , p , size = None ) Summary
Draw samples from a negative binomial distribution.
Extended Summary
Samples are drawn from a negative binomial distribution with specified parameters, n successes and p probability of success where n is > 0 and p is in the interval [0, 1].
Parameters
n: float or array_like of floatsParameter of the distribution, > 0.
p: float or array_like of floatsParameter of the distribution, >= 0 and <=1.
size: int or tuple of ints, optionalOutput 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 scalarDrawn 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.
: .. warning::This function returns the C-long dtype, which is 32bit on windows and otherwise 64bit on 64bit platforms (and 32bit on 32bit ones). Since NumPy 2.0, NumPy's default integer is 32bit on 32bit platforms and 64bit on 64bit platforms.
Notes
The probability mass function of the negative binomial distribution is
where is the number of successes, is the probability of success, is the number of trials, and is the gamma function. When is an integer, , which is the more common form of this term in the pmf. 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.
Examples
Draw 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)
✓See also
- random.Generator.negative_binomial
which should be used for new code.
Aliases
-
numpy.random.negative_binomial -
numpy.random.RandomState.negative_binomial