Skip to content

Instantly share code, notes, and snippets.

@tsutarou10
Created August 18, 2017 01:12
Show Gist options
  • Save tsutarou10/3e83a4ff70853a2e8928f6735e756d73 to your computer and use it in GitHub Desktop.
Save tsutarou10/3e83a4ff70853a2e8928f6735e756d73 to your computer and use it in GitHub Desktop.
ベルヌーイ分布
#coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
def bern(x,p):
return pow(p,x) * pow(1-p,1-x)
if __name__ == "__main__":
dist = np.zeros(2)
for i in range(1,10):
plt.figure()
p = 0.1 * i
dist[0] = bern(0,p)
dist[1] = bern(1,p)
x = np.array([0,1])
label = ["x = 0","x = 1"]
plt.ylim([0.0,1.0])
plt.title("bernoulli distribution (p = " + str(p) + ")")
plt.bar(x,dist,tick_label = label,align = "center")
plt.savefig("bernoulli_" + str(p) + ".png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment