文章作者:Tyan
博客:noahsnail.com | 优快云 | 简书
本文主要是介绍tensorflow中的placeholder及用法。placeholder,中文意思是占位符,在tensorflow中类似于函数参数,运行时必须传入值。
#!/usr/bin/env python
# _*_ coding: utf-8 _*_
import tensorflow as tf
import numpy as np
# 定义placeholder
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)
# 定义乘法运算
output = tf.multiply(input1, input2)
# 通过session执行乘法运行
with tf.Session() as sess:
# 执行时要传入placeholder的值
print sess.run(output, feed_dict = {input1:[7.], input2: [2.]})
执行结果如下图:
[ 14.]

本文介绍了TensorFlow中占位符的概念及其使用方法,并通过一个简单的乘法运算示例展示了如何在TensorFlow程序中定义和使用占位符。占位符在运行时必须传入值,这为构建灵活的计算图提供了便利。
367

被折叠的 条评论
为什么被折叠?



