采用python画激活函数图 tanh、relu、sigmoid

sigmoid:

def sigmoid(x):
    return 1. / (1. + np.exp(-x))

def plot_sigmoid():
    x = np.arange(-10, -10, 0.1)
    y = sigmoid(x)
    plt.plot(x, y)
    plt.show()

tanh:

def tanh(x):
    return (np.exp(x)-np.exp(-x))/(np.exp(x)+np.exp(-x))

def plot_tanh():
    x=np.arange(-10,10,0.1)
    y=tanh(x)
    plt.plot(x,y)
    plt.show()

Relu:

def relu(x):
    return np.maximum(0,x)

def plot_relu():
    x=np.arange(-10,10,0.1)
    y=relu(x)
    plt.plot(x,y)
    plt.show()

 

你可能感兴趣的:(Python)