title: Tensorflow multiplication broadcasting within batches
body: <p>We know that tf.multiply can broadcast like this:</p>
  
  <pre><code>import tensorflow as tf
  import numpy as np
  a = tf.Variable(np.arange(12).reshape(3, 4))
  b = tf.Variable(np.arange(4))
  sess = tf.InteractiveSession()
  sess.run(tf.global_variables_initializer())
  sess.run(tf.multiply(a, b))
  </code></pre>
  
  <p>This will give us </p>
  
  <pre><code>[[0, 1, 4, 9],
   [0, 5, 12, 21],
   [0, 9, 20, 33]]
  </code></pre>
  
  <p>But my question is, what should I do if both <code>a</code> and <code>b</code> are in batches? That is,</p>
  
  <pre><code>a = tf.Variable(np.arange(24).reshape(2, 3, 4))
  b = tf.Variable(np.arange(8).reshape(2, 4))
  </code></pre>
  
  <p>Then how can I get the result of multiplying (broadcasting) the vector onto the matrix in each batch? Like the following answer:</p>
  
  <pre><code>[[[0, 1, 4, 9],
    [0, 5, 12, 21],
    [0, 9, 20, 33]],
  
   [[48, 65, 84, 105],
    [64, 85, 108, 133],
    [80, 105, 132, 161]]]
  </code></pre>
  
  <p>Thanks!</p>