# 1.对数函数

## 1.1 简单的对数函数

import math
import matplotlib.pyplot as plt

if __name__ =="__main__":
x = [float(i)/100 for i in range(1,300)]
y = [math.log(i) for i in x]
plt.plot(x,y,'r-',linewidth=2,label='logCurve')
plt.legend(loc='upper left')
plt.grid(True)
plt.show()

## 1.2 常见对数函数的对比

import math
import numpy as np
import matplotlib.pyplot as plt

if __name__ == "__main__":
x = np.arange(0.05,3,0.01)
#绘制log1.5(x)曲线
y1 = [math.log(a,1.5) for a in x]
plt.plot(x,y1,linewidth=2,color='r',label='log1.5(x)')
y2 = [math.log(a,2) for a in x]
plt.plot(x,y2,linewidth=2,color='g',label='log2(x)')
y3 = [math.log(a,3) for a in x]
plt.plot(x,y3,linewidth=2,color='b',label='log3(x)')
plt.plot([1,1],[y1[0],y1[-1]],'r--',linewidth=2)
#指定标签的位置
plt.legend(loc='lower right')
plt.grid(True)
plt.show()


# 2.常见的函数分布

## 2.1 二项分布

import numpy as np
import matplotlib.pyplot as plt

if __name__ =="__main__":
u = np.random.uniform(0.0,1.0,10000)
plt.hist(u,100,facecolor='g',alpha=0.75,label='Binomial Distribution')
plt.legend(loc="upper left")
plt.grid(True)
plt.show()

# 2.2 泊松分布

import numpy as np
import matplotlib.pyplot as plt

if __name__ =="__main__":
#设定λ为100
x = np.random.poisson(100,10000)
times = 200

plt.hist(x,bins=times,normed=True,range=[0,times],color='g',alpha=0.75,label='Poisson Distribution')
plt.legend(loc="upper left")
plt.grid(True)
plt.show()


# 2.3 指数分布

import numpy as np
import matplotlib.pyplot as plt

if __name__ =="__main__":
#通过赋予不同的λ值，比较不同曲线之间的区别，
lam1 = 0.5
x = np.arange(0,20,0.01)
y1 = lam1 * np.exp(-lam1*x)
plt.plot(x,y1,color='r',label='λ=0.5')

lam2 = 0.3
y2 = lam2 * np.exp(-lam2*x)
plt.plot(x,y2,color='g',label='λ=0.3')

lam3 = 0.1
y3 = lam3 * np.exp(-lam3*x)
plt.plot(x,y3,color='b',label='λ=0.1')

plt.title('Expoential Distribution')
plt.legend(loc='upper right')
plt.grid(True)
plt.show()

## 2.4正态分布

import numpy as np
import matplotlib.pyplot as plt

if __name__ =="__main__":
u = np.random.uniform(0.0,1.0,10000)
times = 10000
for time in range(times):
u += np.random.uniform(0.0,1.0,10000)
u /= times
plt.hist(u,100,facecolor='b',alpha=0.75,label='Gaussian Distribution')
plt.legend(loc="upper left")
plt.grid(True)
plt.show()

12-29 2万+

08-21 7012
09-13 896
04-23 428
08-28 38
12-13 3万+
07-04 705
09-20 59
04-01 5815
05-09 1万+
01-06 154
12-17 481
03-17 1407
05-20
09-18