Is adding a dimension broadcasting?

132 Views Asked by At

Given

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

all of the following are equivalent

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())

and produce

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

I understand that bb is "broadcast" to the value corresponding to bbb by tf.add (here +). Is the addition of a dimension that transforms b to the value of bbb all broadcasting, or is it something else?

1

There are 1 best solutions below

0
On BEST ANSWER

As you mentioned in the comments, b, bb are both valid forms of broadcasting. As mentioned in the numpy documentation,

Arrays do not need to have the same number of dimensions.