tf.math.add(tf.add)

介绍

两个 tensor 相加

两个tensor的 形状 必须符合numpy的广播

别名

  • tf.add 别名有很多,最常用的是 tf.add

语法

tf.math.add(
    x,
    y,
    name=None
)
参数
  • x:必须是下面类型之一:bfloat16, half, float32, float64, uint8, int8, int16, int32, int64, complex64, complex128, string

  • y:必须与x的类型相同

注意:
  • 两个tensor的 形状 必须符合numpy的广播
  • 与两个tensor直接做加法操作相同,即:a+b

例子

a=tf.constant([1,2,3],dtype="int32")
b=tf.constant([4,5,6],dtype="int32")
print(a)
print(b)

tf.add(a,b)

执行结果:

<tf.Tensor: id=525, shape=(3,), dtype=int32, numpy=array([5, 7, 9], dtype=int32)>

与 a+b 操作相同

a+b

执行结果:

<tf.Tensor: id=525, shape=(3,), dtype=int32, numpy=array([5, 7, 9], dtype=int32)>

原文出处:/show_1EF5CyQ9gEWb.html