import numpy as np
import tensorflow as tf
from matplotlib import pyplot as plt
x = tf.linspace(-10.0, 10.0, 100)
x=tf.Variable(x)#计算过程中x需转为变化张量
with tf.GradientTape() as tape: #追踪梯度
s=1/(1+tf.math.exp(-x))
grad=tape.gradient(s,x) #计算梯度
grad
plt.plot(x.numpy(),grad.numpy()) #x.numpy()表示数组
09-26
1007
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交