#numpy shiyong
#np.array();np.empty();np.zeros();np.arange();np.where();np.linspace();np.logspace();np.random()
#疯狂的正弦曲线
import matplotlib.pyplot as plt
import numpy as np
x=np.linspace(-5,5,256)
y=np.sin(x**3)
# print(x)
# print(y)
plt.plot(x,y,'X--')
plt.show()
#正态分布直方图和密度函数图
np.random.seed(12345)
N=10000
randnormal=np.random.normal(size=N)
counts,bins,path=plt.hist(randnormal,bins=int(np.sqrt(N)),color="blue")
print(counts,bins) #频数和分组
print(type(path))
plt.show()
sigma=1;mu=0
norm_dist=(1/np.sqrt(2**np.pi))*np.exp(-((bins-mu)**2)/2)
plt.plot(bins,norm_dist,color="red")
plt.show()
#醉汉步数统计
np.random.seed(1234)
step=np.where(np.random.randint(0,2,10000)>0,1,-1)
posiition=np.cumsum(step)
plt.plot(np.arange(10000),posiition)
plt.show()
#二项分布赌博案例--9枚硬币正面朝上至少5枚输8元,否则赢8元,图示10000次输赢变化,开始时手中有1000元
np.random.seed(1234)
binormal=np.random.binomial(9,0.5,10000)
money=np.zeros(10000)
money[0]=1000
for i in range(1,10000):
if binormal[i]<5:
money[i]=money[i-1]-8
else:
money[i] = money[i - 1] + 8
plt.plot(np.arange(10000),money)
plt.show()