zoukankan      html  css  js  c++  java
  • 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.]

  • 相关阅读:
    iOS开源控件库收集
    Ruby中的几种除法
    Font
    PlaySound
    STL
    APIs
    cin and cout
    CreateWindow
    Introducing Direct2D
    VC 常用代码
  • 原文地址:https://www.cnblogs.com/peterwong666/p/11137142.html
Copyright © 2011-2022 走看看