1.作用:逐元素相乘
tf.math.multiply(
x, y, name=None
)
输入:
x:一个tensor,类型得是bfloat16, half, float32, float64, uint8, int8, uint16, int16, int32, int64, complex64, complex128.
y:跟x同类型。
输出:
逐个元素相乘后的结果。
import tensorflow as tf
a = tf.constant([[3, 2], [5, 1]])
b = tf.constant([[1, 6], [2, 9]])
c = tf.multiply(a, b)
sess = tf.Session()
print sess.run(c)
输出:
[[ 3 12] 【3*1,2*6】
[10 9]] 【5*2,1*9】
变量广播(有一个维度上,相等,便可在另外一个维度上进行广播):
import tensorflow as tf
a = tf.constant([[3, 2]]) #广播 为[[3, 2], [3, 2]]
b = tf.constant([[1, 6], [2, 9]])
c = tf.multiply(a, b)
sess = tf.Session()
print sess.run(c)
输出:
[[ 3 12]
[ 6 18]]
import tensorflow as tf
a = tf.constant([[3]]) #广播 为[[3, 3], [3, 3]]
b = tf.constant([[1, 6], [2, 9]])
c = tf.multiply(a, b)
sess = tf.Session()
print sess.run(c)
输出:
[[ 3 18]
[ 6 27]]