0

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?

orome
  • 45,163
  • 57
  • 202
  • 418
  • Have you read [this](https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)? I don't really understand your question – martianwars Jun 01 '17 at 19:55
  • @martianwars: I think I see. This is `b` is also broadcast: "Arrays do not need to have the same number of dimensions." Matching outer dimension can be added and that's till just broadcasting. (I'll take that or something like it as an answer.) – orome Jun 01 '17 at 20:04

1 Answers1

0

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.

martianwars
  • 6,380
  • 5
  • 35
  • 44