TensorFlow經典案例1:基本操作


import tensorflow as tf


string  = tf.constant("Hello World")


with tf.Session() as sess:
    #在sess中運行op
    print(sess.run(string))

a = tf.constant(2)
b = tf.constant(3)

with tf.Session() as sess:
    print("a = 2 ,b = 3")
    print("計算a+b = %i" % sess.run(a+b))
    print("計算a*b = %i" % sess.run(a*b))

a = tf.placeholder(tf.int16)
b = tf.placeholder(tf.int16)
add = tf.add(a,b)
mul = tf.multiply(a,b)

with tf.Session() as sess:
    print("計算a+b = %i" % sess.run(add,feed_dict={a:2,b:3}))
    print("計算a*b = %i" % sess.run(mul,feed_dict={a:2,b:3}))\

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

product = tf.matmul(matrix1,matrix2)

with tf.Session() as sess:
    result = sess.run(product)
    print(result)

 

公眾號:一個有趣的機器學習社區

(大量機器學習資料分享)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM