I want to generate random sample from geometric distribution using python.
I was using the numpy.random.geometric(p=0.3, size=100) function. But I later realized that this function generates sample from geometric distribution with pmf: p*q^(x-1), x=1,2,3....
But I want random samples from geometric distribution with pmf: p*q^(x), x=0,1,2,...
Kindly help.
But I want random samples from geometric distribution with pmf: p*q^(x), x=0,1,2,...
You can use NumPy's implementation of geometric, and then subtract one from the samples:
In [37]: rng = np.random.default_rng()
In [38]: nsamples = 1000
In [39]: r = rng.geometric(0.3, size=nsamples) - 1
r is a sample from the distribution that you want.
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