tensorflow基础语法

来源:互联网 发布:网络流行歌曲2014 编辑:程序博客网 时间:2024/05/22 10:23

上手试试:

import tensorflow as tfinput1 = tf.constant(3.0)input2 = tf.constant(2.0)input3 = tf.constant(5.0)intermed = tf.add(input2, input3)#1.0版本mul改为multiplymul = tf.multiply(input1, intermed)with tf.Session() as sess:  result = sess.run([mul, intermed])  print(result)

更多更改:

tf.sub()更改为tf.subtract()tf.mul()更改为tf.multiply()tf.types.float32更改为tf.float32tf.pact()更改为tf.stact()

feed机制:
feed 使用一个 tensor 值临时替换一个操作的输出结果. 你可以提供 feed 数据作为 run() 调用的参数. feed 只在调用它的方法内有效, 方法结束, feed 就会消失. 最常见的用例是将某些特殊的操作指定为 “feed” 操作, 标记的方法是使用 tf.placeholder() 为这些操作创建占位符.

import tensorflow as tfinput1 = tf.placeholder(tf.float32)input2 = tf.placeholder(tf.float32)output = tf.multiply(input1, input2)with tf.Session() as sess:    print(sess.run([output], feed_dict={input1:[7.], input2:[2.]}))

未完待续

原创粉丝点击