tensorflow中的占位符

在tensorflow中我们在执行sess之前需要设置占位符,在sess.run中用feed_dict 将其传入

tensorflow中的占位符用 tf.placeholder并且有三个参数

(1)数据类型:

(2)数据大小:

(3)占位符名称:

例如:

import tensorflow as tf
import numpy as np

x = tf.placeholder(tf.float32, [2, 50], name = 'originalx')
y = tf.placeholder(tf.float32, [2,50], name = 'originaly')

c = x+y

with tf.Session() as sess:
    a = np.random.randint(0,80,100).reshape((2,50))
    aa = np.random.random(100).reshape((2,50))
    result = sess.run(c, feed_dict = {x:a, y:aa})
    print(result)

猜你喜欢

转载自blog.csdn.net/m0_37548423/article/details/85209390