tensorflow 使用 2 Felch ,Feed

本文介绍了使用TensorFlow进行基本数学运算的方法,包括如何定义常量、执行加法与乘法操作,以及通过feed_dict参数传递数据到占位符来实现动态输入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Felch ::在会话里可以执行多个 op ,

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 

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.]

 

转载于:https://www.cnblogs.com/gdwz922/p/10624566.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值