本文主要是介紹tensorflow中的placeholder及用法幻赚。placeholder,中文意思是占位符,在tensorflow中類似于函數(shù)參數(shù),運行時必須傳入值择诈。
import tensorflow as tf
import numpy as np
# 定義placeholder
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)
# 定義乘法運算
output = tf.multiply(input1, input2)
# module 'tensorflow' has no attribute 'mul'
# 通過session執(zhí)行乘法運行
with tf.Session() as sess:
# 執(zhí)行時要傳入placeholder的值
print (sess.run(output, feed_dict = {input1:[7.], input2: [2.]}))