一、阶跃函数
import numpy as np
import matplotlib.pylab as plt
def step_function(x):return np.array(x>0)x = np.arange(-5.0,5.0,0.1)
y = step_function(x)
plt.plot(x, y)
plt.ylim(-0.1, 1.1)
plt.show()
二、sigmoid函数
import numpy as np
import matplotlib.pyplot as plt
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['STZhongsong'] # 指定默认字体:解决plot不能显示中文问题
mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题
def sigmoid(x):return 1/(1+np.exp(-x))
x = np.arange(-10,10,0.06)
y = sigmoid(x)
plt.plot(x,y,'r+')
plt.xlabel('x')
plt.ylabel('y')
plt.title('sigmoid( )函数')
plt.show()
三、ReLU函数
import numpy as np
import matplotlib.pyplot as plt
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['STZhongsong'] # 指定默认字体:解决plot不能显示中文问题
mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题
def ReLU(x):return np.maximum(0,x)x = np.arange(-6, 6, 0.1)
y = ReLU(x)
plt.plot(x,y,linewidth=2)
plt.xlabel('x')
plt.ylabel('ReLU(x)')
plt.title('ReLU函数图像')
plt.show()