tf.compat.v1.placeholder

1 placeholder是占位符,相当于定义了一个变量,提前分配了需要的内存。但只有启动一个session,程序才会真正的运行。建立session后,通过feed_dict()函数向变量赋值。

2 定义

tf.compat.v1.placeholder(dtype,shape=None,name=None)

  dtype数据类型、shape数据形状、name名称

3 实例

import tensorflow as tf
import numpy as np
 
input1 = tf.compat.v1.placeholder(tf.float32)
input2 = tf.compat.v1.placeholder(tf.float32)
 
output = tf.multiply(input1, input2)
 
with tf.Session() as sess:
    print(sess.run(output, feed_dict = {input1:[3.], input2: [4.]}))

猜你喜欢

转载自blog.csdn.net/Fwuyi/article/details/125679823