TensorFlow——小练习:feed

feed就是喂入数据

使用feed前必须要有占位符作为操作的对象,在运行操作的时候喂入数据。

 1 # _*_coding:utf-8_*_
 2 import tensorflow as tf
 3 import numpy as np
 4 
 5 input1 = tf.placeholder(tf.float32)    # 占位符要指明元素数据类型,在运行操作时,若算子有占位符,需要在运行时,通过feed_dict来指feed的数据
 6 input2 = tf.placeholder(tf.float32)
 7 
 8 output = tf.mul(input1, input2)
 9 
10 with tf.Session() as sess:
11     print(sess.run(output, feed_dict={input1:[7.0], input2:[2.]}))

 运行结果:

[ 14.]
原文地址:https://www.cnblogs.com/DianeSoHungry/p/7144751.html