莫烦tensorflow教程笔记(三)

来源:互联网 发布:charindex函数 sql 编辑:程序博客网 时间:2024/05/29 07:20

tensorflow中placeholder的用法

import tensorflow as tfimort numpy as np

input1 = tf.placeholder(tf.float32)         input2 = tf.placeholder(tf.float32)      #为输入input1和input2预留空间,此处也可以指定shape,见下面的例子output = tf.multiply(input1,input2)      # 教程中使用的是mul

with tf.Session() as session:    print(session.run(output,feed_dict={input1:[7.],input2:[2.]}))     #输出结果为[14.]

input3 = tf.placeholder(tf.float32,[1,3])input4 = tf.placeholder(tf.float32,[1,3])        #输入的是1行3列的数组output = tf.multiply(input3,input4)             #对应位分别相乘

with tf.Session() as session:    print(session.run(output,feed_dict={input3:np.array([1,2,3]),input4:np.array([1,2,3])}))     # 将array([1,2,3])分别赋值给input3,input4  ,输出结果为[[1.,4.,9.]]


原创粉丝点击