Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sigmoid

import tensorflow as tf
from matplotlib import pyplot as plt
x = tf.linspace(-5.,5,20)
x = tf.nn.sigmoid(x)

plt.figure(facecolor='white')
plt.plot(x)
plt.show()

numpy实现的sigmoid函数

from matplotlib import pyplot as plt
import numpy as np

x = np.linspace(-5,5,20)
x = list(map(lambda x: 1/(1+np.exp(-x)),x))
plt.figure(facecolor='white')
plt.plot(x)
plt.show()

函数图像

relu

< 0 就化为0

from tensorflow.keras import activations
activations.relu([1,2,3,-1,0])

out:
<tf.Tensor: shape=(5,), dtype=int32, numpy=array([1, 2, 3, 0, 0])>