美文网首页
tensorflow中的placeholder

tensorflow中的placeholder

作者: 大梦一场三十一 | 来源:发表于2018-03-04 08:57 被阅读0次

本文主要是介绍tensorflow中的placeholder及用法。placeholder,中文意思是占位符,在tensorflow中类似于函数参数,运行时必须传入值。

import tensorflow as tf
import numpy as np

# 定义placeholder
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)

# 定义乘法运算
output = tf.multiply(input1, input2)
# module 'tensorflow' has no attribute 'mul'

# 通过session执行乘法运行
with tf.Session() as sess:
    # 执行时要传入placeholder的值
    print (sess.run(output, feed_dict = {input1:[7.], input2: [2.]}))

相关文章

网友评论

      本文标题:tensorflow中的placeholder

      本文链接:https://www.haomeiwen.com/subject/axkffftx.html