tf.placeholder()函数

tf.placeholder()函数作为一种占位符用于定义过程,可以理解为形参,在执行的时候再赋具体的值。

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

参数:

  • dtype:数据类型。常用的是tf.float32,tf.float64等数值类型
  • shape:数据形状。默认是None,就是一维值,也可以多维,比如:[None,3],表示列是3,行不一定
  • name:名称

返回:

Tensor类型

此函数可以理解为形参,用于定义过程,在执行的时候再赋具体的值。

不必指定初始值,可在运行时,通过 Session.run 的函数的 feed_dict 参数指定。

这也是其命名的原因所在,仅仅作为一种占位符。

import tensorflow as tf
in1 = tf.placeholder(tf.float32)
in2 = tf.placeholder(tf.float32)
out = tf.multiply(in1,in2)
with tf.Session() as sess:
    #print(sess.run(out))
    print(sess.run(out, feed_dict={in1: [7.], in2: [2.]}))

[14.]

猜你喜欢

转载自www.cnblogs.com/tingtin/p/12558236.html