import numpy as np
import matplotlib.pyplot as plt
# matplotlib的负数显示设置
plt.rcParams['axes.unicode_minus'] = False # 显示负数
# 输出高清图像
%config InlineBackend.figure_format = 'retina'
%matplotlib inline
# 设置字体
plt.rc('font',family='Times New Roman', size=15)
# 1.1 定义sigmoid函数
def sigmoid(x):
return 1. / (1 + np.exp(-x))
# 1.2 定义tanh函数
def tanh(x):
return (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x))
# 1.3 定义relu函数
def relu(x):
return np.where(x < 0, 0, x)
# 1.4 定义softmax函数
def softmax(x):
return np.exp(x)/np.sum(np.exp(x),axis=0)
# 2.1 定义绘制函数sigmoid函数
def plot_sigmoid():
x = np.arange(-10, 10, 0.1)
y = sigmoid(x)
fig = plt.figure()#如果使用plt.figure(1)表示定位(创建)第一个画板,如果没有参数默认创建一个新的画板,如果plt.figure(figsize = (2,2)) ,表示figure 的大小为宽、长
ax = fig.add_subplot(111)#表示前面两个1表示1*1大小,最后面一个1表示第1个
ax.spines['top'].set_color('none')#ax.spines设置坐标轴位置,set_color设置坐标轴边的颜色
ax.spines['right'].set_color('none')
ax.spines['left'].
python绘制激活函数(sigmoid, Tanh, ReLU, Softmax)
最新推荐文章于 2025-07-11 13:51:16 发布