tensorflow 使用 2 Felch ,Feed

Felch ::在会话里能够执行多个 op ,ui

import tensorflow as tf


input1 = tf.constant(3.0)
input2 = tf.constant(2.0)
input3 = tf.constant(5.0)

# 加法操做
add = tf.add(input2, input3)
# 乘法操做
mul = tf.multiply(input1, add)

with tf.Session() as sess:
  # d在【】中写入 上述的两个 op ,能够同时执行
  res = sess.run([add, mul])
  print(res)
[7.0, 21.0]

 

Feed spa

import tensorflow as tf

# 建立个占位符,32位的浮点型
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)

# 乘法操做
uitput = tf.multiply(input1, input2)

with tf.Session() as sess:
  # Feed 的数据以字典的形式传入
  print( sess.run(uitput, feed_dict={input1:[7.0], input2:[2.]}) )

  

[14.]
相关文章
相关标签/搜索