最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python3 用matplotlib繪制sigmoid函數(shù)的案例

 更新時間:2020年12月11日 10:09:36   作者:hiudawn  
這篇文章主要介紹了Python3 用matplotlib繪制sigmoid函數(shù)的案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

我就廢話不多說了,大家還是直接看代碼吧~

import matplotlib.pyplot as plt
import numpy as np 
def sigmoid(x):
  # 直接返回sigmoid函數(shù)
  return 1. / (1. + np.exp(-x)) 
 
def plot_sigmoid():
  # param:起點,終點,間距
  x = np.arange(-8, 8, 0.2)
  y = sigmoid(x)
  plt.plot(x, y)
  plt.show() 
 
if __name__ == '__main__':
  plot_sigmoid()

如圖:

補充知識:python:實現(xiàn)并繪制 sigmoid函數(shù),tanh函數(shù),ReLU函數(shù),PReLU函數(shù)

如下所示:

# -*- 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)
  y = sigmoid(x)
  fig = plt.figure()
  # ax = fig.add_subplot(111)
  ax = axisartist.Subplot(fig,111)
  ax.spines['top'].set_color('none')
  ax.spines['right'].set_color('none')
  # ax.spines['bottom'].set_color('none')
  # ax.spines['left'].set_color('none')
  ax.axis['bottom'].set_axisline_style("-|>",size=1.5)
  ax.spines['left'].set_position(('data', 0))
  ax.plot(x, y)
  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)
  y = tanh(x)
  fig = plt.figure()
  ax = fig.add_subplot(111)
  ax.spines['top'].set_color('none')
  ax.spines['right'].set_color('none')
  # ax.spines['bottom'].set_color('none')
  # ax.spines['left'].set_color('none')
  ax.spines['left'].set_position(('data', 0))
  ax.spines['bottom'].set_position(('data', 0))
  ax.plot(x, y)
  plt.xlim([-10.05, 10.05])
  plt.ylim([-1.02, 1.02])
  ax.set_yticks([-1.0, -0.5, 0.5, 1.0])
  ax.set_xticks([-10, -5, 5, 10])
  plt.tight_layout()
  plt.savefig("tanh.png")
  plt.show() 
 
def plot_relu():
  x = np.arange(-10, 10, 0.1)
  y = relu(x)
  fig = plt.figure()
  ax = fig.add_subplot(111)
  ax.spines['top'].set_color('none')
  ax.spines['right'].set_color('none')
  # ax.spines['bottom'].set_color('none')
  # ax.spines['left'].set_color('none')
  ax.spines['left'].set_position(('data', 0))
  ax.plot(x, y)
  plt.xlim([-10.05, 10.05])
  plt.ylim([0, 10.02])
  ax.set_yticks([2, 4, 6, 8, 10])
  plt.tight_layout()
  plt.savefig("relu.png")
  plt.show() 
 
def plot_prelu():
  x = np.arange(-10, 10, 0.1)
  y = prelu(x)
  fig = plt.figure()
  ax = fig.add_subplot(111)
  ax.spines['top'].set_color('none')
  ax.spines['right'].set_color('none')
  # ax.spines['bottom'].set_color('none')
  # ax.spines['left'].set_color('none')
  ax.spines['left'].set_position(('data', 0))
  ax.spines['bottom'].set_position(('data', 0))
  ax.plot(x, y)
  plt.xticks([])
  plt.yticks([])
  plt.tight_layout()
  plt.savefig("prelu.png")
  plt.show() 
 
if __name__ == "__main__":
  plot_sigmoid()
  plot_tanh()
  plot_relu()
  plot_prelu()

以上這篇Python3 用matplotlib繪制sigmoid函數(shù)的案例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

锦屏县| 尖扎县| 凤山县| 东山县| 孙吴县| 土默特左旗| 乌苏市| 辉县市| 桑日县| 阜南县| 德化县| 松原市| 武汉市| 金华市| 万全县| 普兰店市| 赤城县| 壶关县| 江阴市| 新竹市| 呼和浩特市| 嫩江县| 永善县| 来宾市| 翼城县| 泸溪县| 花莲县| 江北区| 漳平市| 金堂县| 嘉义县| 遂昌县| 夏邑县| 广水市| 乌恰县| 桓仁| 广德县| 东阳市| 沧州市| 商洛市| 洱源县|