Reputation: 21
I would like to get a non-uniform sample (500 int) with numpy. I tried numpy.random.randint, but I get a uniform sample. Any simple solutions ? Thanks for yours answers.
Upvotes: 2
Views: 2514
Reputation: 1097
If you just want to generate samples from a distribution, staying in NumPy is probably easier. (Scipy provides methods for the PDFs themselves, which can become more complicated.) There are dozens of non-uniform distributions to choose from in the numpy.random
module. For example, if you're after discrete, integer, nonnegative samples:
sample = np.random.poisson(5, size=1000)
plt.hist(sample)
Upvotes: 0
Reputation: 802
You can find a lot of non-uniform distributions in scipy.stats
, and use them in such way:
from scipy.stats import <distribution_you_want>
sample = <distribution_you_want>.rvs(size=500)
Upvotes: 1