加法
tf.add
tf.add(x,y,name=None)
参数说明:
x:一个张量,必须是下列类型之一:bfloat16/half/float32/uint8/int8/int16/int32/int64/complex64/complex128/string
y: 一个张量,类型必须同x
name:操作的名字,可选参数
返回值: x+y
一个张量,类型同x
import tensorflow as tf
a = tf.constant(2)
b = tf.constant(5)
addOp = tf.add(a,b)
sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)
print(sess.run(addOp))
print(addOp)
sess.close()
输出:
7
Tensor("Add:0", shape=(), dtype=int32)
tf.math.add
同tf.add
减法
tf.subtract
tf.subtract(x,y,name=None)

本文详细介绍了TensorFlow中基本的数学运算操作,包括加法、减法、乘法、除法以及标量与张量的乘法。通过具体的代码示例展示了如何使用这些运算符进行张量操作。
最低0.47元/天 解锁文章
450

被折叠的 条评论
为什么被折叠?



