title: Weighted sum of matrices in Tensorflow
body: <p>I have a 3-dimensional tensor A of size (M,N,N) and an 1 dimensional tensor p of size M. I want to compute the weighted sum of matrices:</p>
  
  <p><a href="https://i.stack.imgur.com/9v5FU.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9v5FU.gif" alt="enter image description here"></a></p>
  
  <p>In NumPy I am implementing the following code:</p>
  
  <pre><code>import numpy as np
  temp=np.array([p[m]*A[m] for m in range(M)])
  B=sum(temp);
  </code></pre>
  
  <p>I want to do the same in TensorFlow but I don't seem to find any inbuilt operations to carry out the same. I tried <code>tf.matmul</code> and <code>tf.mul</code> but they don't seem to be giving the desired result. Can someone suggest me a right way to do this in TensorFlow?</p>