TensorFlow 之tf.placeholder()
tf.placeholder(
dtype,
shape=None,
name=None
)
# In[]
#dtype:被填充的张量(Tensor)的元素类型。
#shape:被填充张量(Tensor)的形状(可选参数)。如果没有指定张量(Tensor)打形状,你可
#以填充该张量(Tensor)为任意形状。
#name:为该操作提供一个名字(可选参数)。import tensorflow as tf
# 定义placeholder
input1 = tf.placeholder(tf.float32,shape=(1, 2),name="input-1")
input2 = tf.placeholder(tf.float32,shape=(2, 1),name="input-2")
# 定义矩阵乘法运算(注意区分matmul和multiply的区别:matmul是矩阵乘法,multiply是点乘)
output = tf.matmul(input1, input2)
# 通过session执行乘法运行
with tf.Session() as sess:
# 执行时要传入placeholder的值
print(sess.run(output, feed_dict = {input1:[1,2], input2:[3,4]}))
# 最终执行结果 [11] 相关推荐
JM 2020-05-04
haidaoxianzi 2020-04-18
81570790 2020-04-16
攻城师 2013-05-14
haohong 2020-01-17
JM 2019-12-22
cherry0 2019-12-13
拭血 2019-11-17
hnyzyty 2019-11-04
zyhui 2019-09-08
wcssdu 2017-11-01
jiedinghui 2018-04-03
zZoOoOJaVa 2018-02-19
MayMatrix 2015-01-09
hualala 2019-07-01
LiteHeaven 2019-06-30
mjbaishiyun 2019-06-30