【Tensorflow】placeholder & feed_dict

placeholder占位。

feed_dict 字典类型。向占位符送数据。

import tensorflow as tf
w1 = tf.Variable(tf.random_normal([2,3],stddev=1))
w2 = tf.Variable(tf.random_normal([3,1],stddev=1))

x = tf.placeholder(tf.float32,shape=(1,2),name="input")
a = tf.matmul(x,w1) # 矩阵乘法
y = tf.matmul(a,w2)

sess = tf.Session()
sess.run(tf.global_variables_initializer()) #初始化模型的参数
print(sess.run(y,feed_dict={x:[[0.7,0.9]]}))  #注意[[]]

输出:

[[-2.2629368]]

猜你喜欢

转载自blog.csdn.net/xykimred/article/details/84865540