1

I must simulate 100,000 geometric random variables with parameter p = 0.01 and plot the results on a histogram, with buckets for each of the values 1 to 1000. What are buckets and how to I create the histogram? This is what I have so far.

p = 0.01
n = 100000
import numpy as np
import matplotlib.pyplot as plt 
y = np.random.geometric(p,n)
Chance Gordon
  • 143
  • 1
  • 8
  • 1
    What do you mean by "simulate" and what is this bucket? If you just want a histogram, you can use `plt.hist(y, bins=100);` – Sheldore Jan 17 '19 at 21:26

1 Answers1

1

'Buckets' are the same as 'Bins', which are the range of values your data will fall into. So if your data ranges from 1-1000 and you want a bucket for each then you will need 1000 of them. If say you only had 100 bins it would group you data into 10's (1-10,11-20,21-30...)

Using matplotlib.pyplot which you already have imported you can use:

plt.figure()
plt.hist(y,bins=1000)
plt.show()
Jonski Goldstein
  • 169
  • 5
  • 16