python tensorflow.assign赋值操作方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python tensorflow.assign赋值操作方法相关的知识,希望对你有一定的参考价值。

import tensorflow as tf
x = tf.Variable(0)
y = tf.assign(x, 1)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print sess.run(x)
    print sess.run(y)
    print sess.run(x)
--------------------- 
In [212]: w = tf.Variable(12)
In [213]: w_new = w.assign(34)
 
In [214]: with tf.Session() as sess:
     ...:     sess.run(w_new)
     ...:     print(w_new.eval())
 
# output
34 
--------------------- 
import tensorflow as tf
x = tf.Variable(0)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
print(sess.run(x))  # Prints 0.
x.load(1, sess)
print(sess.run(x))  # Prints 1.

以上是关于python tensorflow.assign赋值操作方法的主要内容,如果未能解决你的问题,请参考以下文章

python程序输入一个包含3个整数的list,将它们从小到大赋给一个列表,怎么写程序?

Python,将文件中的列表读取出来并作为列表赋给变量

零基础学python-3.2 变量赋值

Python 的变量类型都可以隐式转换吗

三.Python数据类型详述

Python赋值