I have a simple yet broad question regarding two methods:
scipy.stats.randint
and
numpy.random.randint
After reading the API for both methods I'm a bit confused as to when it is best to use each method; therefore, I was wondering if someone could outline the differences between the two and possibly offer some examples of when one method would be preferable to use over the other. Thanks!
Edit: Links to each method's documentation -> numpy.random.randint, scipy.stats.randint
numpy.random. randint (low, high=None, size=None, dtype='l') ¶ Return random integers from low (inclusive) to high (exclusive). Return random integers from the “discrete uniform” distribution of the specified dtype in the “half-open” interval [ low, high). If high is None (the default), then results are from [0, low).
Numpy random.randint() also can generate a random integer. numpy.random.randint(low, high=None, size=None, dtype='l') The value of result is in [low, high). However, as to python random.randint(), the value of result is in[low, high]. This is the main difference between them. For example:
numpy.random.randint () is one of the function for doing random sampling in numpy. It returns an array of specified shape and fills it with random integers from low (inclusive) to high (exclusive), i.e. in the interval [low, high).
A uniform discrete random variable. As an instance of the rv_discrete class, randint object inherits from it a collection of generic methods (see below for the full list), and completes them with details specific for this particular distribution. for k ∈ { low, …, high − 1 }. randint takes low and high as shape parameters.
The major difference seems to be that scipy.stats.randint
allows you to explicitly name the lower or upper tail probability, as well as specify the distributions you want to draw the random ints from (see the methods section of the scipy.stats.randint documentation). It's therefore much more useful if you want to draw random intervals from a given density function.
If you really just want to draw a random integer that falls within a certain range, with no requirements regarding the distribution, then numpy.random.randint
is more straightforward. They would be drawn directly from a discrete uniform distribution, with no built in option to modify that.
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