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

1.函数功能:

插入一个张量的占位符,这个张量总是被喂入图片数据。相当于一个形参。

形参:只有在被调用时才分配内存单元,在调用结束时,就会释放出所分配的内存单元。

2.函数参数:

dtype:数据类型;shape:数据维度;name:数据名称

3.代码实现:

import tensorflow as tf
input1 = tf.placeholder(tf.float32,[1,2],name="a")
input2 = tf.placeholder(tf.float32,[2,1],name="b")
output1 = tf.multiply(input1,input2) #两个矩阵中对应元素各自相乘
output2 = tf.matmul(input1,input2) #将矩阵a乘以矩阵b,生成a * b。
with tf.Session() as sess:
    print(sess.run(output1,feed_dict={input1:[[1.,2.]],input2:[[3.],[4.]]}))
    print(sess.run(output2, feed_dict={input1: [[1., 2.]], input2: [[3.], [4.]]}))

猜你喜欢

转载自blog.csdn.net/william_hehe/article/details/81612640