我遇到You must feed a value for placeholder tensor 'Placeholder' with dtype float and shape [2,2]
错误。我已经喂过占位符aa
import numpy as np
import tensorflow as tf
aa = tf.placeholder(dtype=tf.float32, shape=(2, 2))
bb = tf.Variable(aa)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(sess.run(bb,feed_dict={aa:np.random.rand(2,2)}))
答案 0 :(得分:1)
问题出在sess.run(init)
中;您需要aa
的值才能初始化bb
。不过,aa
以后不需要检索bb
,因为已经为其分配了值。
import numpy as np
import tensorflow as tf
aa = tf.placeholder(dtype=tf.float32, shape=(2, 2))
bb = tf.Variable(aa)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init, feed_dict={aa: np.random.rand(2, 2)})
print(sess.run(bb))