美文网首页
tensorflow实战-2.变量

tensorflow实战-2.变量

作者: 科幻不再未来 | 来源:发表于2016-10-17 20:15 被阅读0次
#coding=utf-8

#tensorflow变量
import tensorflow as tf

matrix1 = tf.constant([[3., 3.]])

#申明x变量,并初始化
x = tf.Variable([[1.0, 2.0]])
new_value = tf.add(x, matrix1)
#new_value赋值给x
update = tf.assign(x, new_value)

init_op = tf.initialize_all_variables()

sess = tf.Session()

with tf.Session() as sess:
  #需要先初始化
  sess.run(init_op)
  print(sess.run(x))
  for _ in range(3):
    #变量都需要通过sess.run执行
    sess.run(update)
    print(sess.run(x))

相关文章

网友评论

      本文标题:tensorflow实战-2.变量

      本文链接:https://www.haomeiwen.com/subject/tdxzyttx.html