我正在尝试评估aX^2+bX+c,就像[a,b,c]\*[X*X X 1]在张量流中一样。
我试过以下代码:
import tensorflow as tf
X = tf.placeholder(tf.float32, name="X")
W = tf.Variable([1,2,1], dtype=tf.float32, name="weights")
W=tf.reshape(W,[1,3])
F = tf.Variable([X*X,X,1.0], dtype=tf.float32, name="Filter")
F=tf.reshape(F,[3,1])
print(W.shape)
print(F.shape)
Y=tf.matmul(W,F)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for i in range(10):
sess.run(Y, feed_dict={X: i})
Y=sess.run(Y)
print("Y:",Y)
但是,初始化程序并不高兴:
(1, 3)
(3, 1)
...
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'X' with dtype float
[[{{node X}}]]
During handling of the above exception, another exception occurred:
...
Caused by op 'X', defined at:
File "sample.py", line 2, in <module>
X = tf.placeholder(tf.float32, name="X")
...
关于可能的替代方案有什么想法吗?
哔哔one
MM们
相关分类