当前位置:网站首页>机器学习:梯度下降法

机器学习:梯度下降法

2022-06-24 19:28:00 翁炜强

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()表示数组
       

原网站

版权声明
本文为[翁炜强]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_52124121/article/details/119802608