tf.assign的用法


tf.assign(A, new_number): 这个函数的功能主要是把A的值变为new_number

例如:

import tensorflow as tf;
 
A = tf.Variable(tf.constant(0.0), dtype=tf.float32)
with tf.Session() as sess:
    sess.run(tf.initialize_all_variables())
    print sess.run(A)
    sess.run(tf.assign(A, 10))
    print sess.run(A)

输出:

0.0
10.0

开始给A赋值为0,经过tf.assign函数后,把A的值变为10

==========

再例如: 

 

import tensorflow as tf

input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)

ouput = tf.multiply(input1,input2)

with tf.Session() as sess:
    print(sess.run(ouput,feed_dict={input1:[7.],input2:[2.]}))

输出:

[14.]


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM