TensorFlow——小练习:feed

Posted DianeSoHungry

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.]

 

以上是关于TensorFlow——小练习:feed的主要内容,如果未能解决你的问题,请参考以下文章

tensorflow2.0 新特性小练习

TensorFlow feed_dict 没有学习

TensorFlow中数据读取之tfrecords

TensorFlow力学101笔记[4]

tensorflow 中 feed的用法

Tensorflow:feed_dict 的形状错误