首页 > 编程知识 正文

python sqrt函数,pythonlinespace函数用法

时间:2023-05-06 06:22:04 阅读:183943 作者:1159

python实现并绘制 sigmoid函数,tanh函数,cjdbq,Pcjdbq

# -*- coding:utf-8 -*-

from matplotlib import pyplot as plt

import numpy as np

import mpl_toolkits.axisartist as axisartist

def sigmoid(x):

return 1. / (1 + np.exp(-x))

def tanh(x):

return (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x))

def relu(x):

return np.where(x<0,0,x)

def prelu(x):

return np.where(x<0,0.5*x,x)

def plot_sigmoid():

x = np.arange(-10, 10, 0.1)

fig = plt.figure()

# ax = fig.add_subplot(111)

# ax.spines[‘bottom‘].set_color(‘none‘)

# ax.spines[‘left‘].set_color(‘none‘)

plt.xlim([-10.05, 10.05])

plt.ylim([-0.02, 1.02])

plt.tight_layout()

plt.savefig("sigmoid.png")

plt.show()

def plot_tanh():

x = np.arange(-10, 10, 0.1)

fig = plt.figure()

# ax.spines[‘bottom‘].set_color(‘none‘)

# ax.spines[‘left‘].set_color(‘none‘)

plt.xlim([-10.05, 10.05])

plt.ylim([-1.02, 1.02])

plt.tight_layout()

plt.savefig("tanh.png")

plt.show()

def plot_relu():

x = np.arange(-10, 10, 0.1)

fig = plt.figure()

# ax.spines[‘bottom‘].set_color(‘none‘)

# ax.spines[‘left‘].set_color(‘none‘)

plt.xlim([-10.05, 10.05])

plt.ylim([0, 10.02])

plt.tight_layout()

plt.savefig("relu.png")

plt.show()

def plot_prelu():

x = np.arange(-10, 10, 0.1)

fig = plt.figure()

# ax.spines[‘bottom‘].set_color(‘none‘)

# ax.spines[‘left‘].set_color(‘none‘)

plt.xticks([])

plt.yticks([])

plt.tight_layout()

plt.savefig("prelu.png")

plt.show()

if __name__ == "__main__":

plot_sigmoid()

plot_tanh()

plot_relu()

plot_prelu()

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。