import tensorflow as tf
# matrix1 = tf.constant([[3, 3]])
# matrix2 = tf.constant([[2], [2]])
# product = tf.matmul(matrix1, matrix2) #操作:矩阵相乘
#
# #method 1
# with tf.Session() as sess:
# result=sess.run(product)
# print(result)
####定义变量#######
state = tf.Variable(0,name='counter')
one = tf.constant(1)
new_value = tf.add(state, one)
update = tf.assign(state, new_value) #操作:将new_value赋值更新到state
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
for _ in range(3):
sess.run(update)
print(sess.run(state))tensorflow练习02-矩阵与变量
最新推荐文章于 2024-06-26 00:16:52 发布
本文通过一个简单的计数器示例介绍了如何在TensorFlow中定义变量并进行更新操作。首先定义了一个计数器变量state,并创建了一个会话来运行初始化操作及变量更新操作。在会话中运行了三次更新操作后输出了最终的计数器状态。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
TensorFlow-v2.15
TensorFlow
TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型
3224

被折叠的 条评论
为什么被折叠?



