Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scipy randint vs numpy randint

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

like image 240
DGav Avatar asked Feb 28 '18 19:02

DGav


People also ask

How do you use randint in NumPy?

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).

What is the difference between NumPy random() and Python random()?

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:

How do you randomize a NumPy array?

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).

What is the randint method in Java?

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.


1 Answers

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.

like image 173
sacuL Avatar answered Oct 18 '22 06:10

sacuL