添加维度广播?

时间:2017-06-01 19:43:34

标签: tensorflow numpy-broadcasting tensorflow-xla

鉴于

a = tf.constant([[1, 2, 3], [10, 20, 30], [100, 200, 300], [1000, 2000, 3000]])

以下所有内容均为

b = tf.constant([100000, 200000, 300000])
print((a+b).eval())

bb = tf.constant([[100000, 200000, 300000]])
print((a+bb).eval())

bbb = tf.constant([[100000, 200000, 300000], [100000, 200000, 300000], [100000, 200000, 300000], [100000, 200000, 300000]])
print((a+bbb).eval())

并制作

[[100001 200002 300003]
 [100010 200020 300030]
 [100100 200200 300300]
 [101000 202000 303000]]

我知道bb是"广播"通过bbb(此处为tf.add)与+对应的值。添加的维度是将b转换为bbb所有广播的值,还是其他内容?

1 个答案:

答案 0 :(得分:0)

正如您在评论中提到的,bbb都是有效的广播形式。正如numpy documentation中提到的那样,

  

数组不需要具有相同数量的维度。

相关问题