Na deviaty deň funkcia numpyho kroku, funkcia sigmoidu a funkcia RELU
Ninth Day Numpys Step Function
Skôr ako začnete, mali by ste vedieť, ako sa učiť pomocou funkcií poľa numpy. Naučte sa dnes tri funkcie súvisiace s hlbokým učením.
Jeden je kroková funkcia, jeden sigmoidná funkcia a druhá funkcia relu, ktorá sa zobrazuje pomocou matplotlib. Všetky tieto tri generujú krokové funkcie, ale dve sú krivky. Druhou je hladká krivka, poďme sa najskôr pozrieť na kód.
import numpy as np import matplotlib as plt def function(x): return np.array(x>0,dtype = np.int) Ty =np.arange(-5.0,5.0,0.1) #Generate a matrix from -5.0 to 5.0 with a step of 0.1 T = function(Ty) plt.plot(Ty,T) plt.ylim(-0.1,1.1) plt.show 1 2 def function(x): 3 return np.array(x>0,dtype = np.int) 4 Ty =np.arange(-5.0,5.0,0.1) #Generate a matrix from -5.0 to 5.0 with a step of 0.1 5 T = function(Ty) 6 plt.plot(Ty,T) 7 plt.ylim(-0.1,1.1) 8 plt.show Out[27]: !Step function](https://img-blog.csdnimg.cn/20190311213559393.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMwMDc4NzUx,size_16,color_FFFFFF,t_70) 1 def sigmoid_fun(x): 2 return 1/(1+np.exp(-x)) 3 R_l = np.arange(-5.0,5.0,0.1) 4 5 R_y = sigmoid_fun(R_l) 6 7 plt.plot(R_l,R_y) 8 9 plt.ylim(-0.1,1.1) 10 plt.show() 11 12  13 14 Def Relu_function(x): # Enter a number, if it is less than or equal to 0, it will output 0. If it is greater than 0, it will be returned. return np.maximum(0,x) R_x = np.arange(-1.2,2.5,0.05) # Generate -1.2 to 2.5 array with 0.1 step R_Y = Relu_function(R_x) plt.plot(R_x,R_Y) plt.ylim(-2.0,3) plt.show() Output: 
Exp (-x) vo funkcii je v skutočnosti e ^ (- x) a e je Napierova konštanta 2,7182. . . .