以下範例可在r1.3版本Tensorflow正確執行,若為其他版本需要再參考API手冊改寫
常數相乘:
import tensorflow as tf
x1 = tf.constant(5)
x2 = tf.constant(6)
result = tf.multiply(x1,x2)
sess = tf.Session()
print(sess.run(result))
變數相乘:
import tensorflow as tf
x1 = tf.Variable([5])
x2 = tf.Variable([6])
result = tf.multiply(x1,x2)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
print(sess.run(result))
沒有留言:
張貼留言