pythonsyntaxgamma-distribution

Generating gamma random samples in python


can someone help me to generate random numbers from the gamma distribution in python, i have tried these two possibilities but i'm still wondering about the main difference between them : The first one is :

shape, scale= 0.5,1
size=(1024,10)
np.random.gamma(shape, scale, size)

and the second one is :

from scipy.stats import gamma 
gamma.rvs(0.5, 1, (1024,10))

i think both of them are used to generate random samples following the gamma distribution, so what's the difference between these syntaxes. When should we use the first method and when the second one ?


Solution

  • There is no difference between the two except for the fact that one is from numpy and other from scipy library. The probability density function used to create gamma distribution is same in both the cases.