title: Pytorch Inner Product of 3D tensor with 1D Tensor to generate 2D Tensor
body: <p>Operation : I have pytorch tensor <code>A</code> of dimension <code>[n x m x c]</code> and <code>B</code> of dimension <code>[1 x 1 x c]</code>. I want to take inner product of each of <code>1 x 1 x c</code> vector from <code>A</code> with <code>B</code> and hence generate a tensor <code>C</code> of dimension <code>[n x m]</code>.</p>
  
  <p>Inside forward function of my network at a specific step I receive tensor of dimension <code>[N, channels, Height, Width]</code> where N is number of images, channels is number of channels in the feature map, and height and width are of the current feature map. I also have an <code>[N x channels]</code> feature map from some other subnetwork. In the next step I want to carry out the above mentioned operation.</p>
  
  <p>Can somebody explain the best way and functions available in pytorch to achieve such step.</p>
  
  <p>I am new to pytorch and was unable to find a proper way. Tensorflow supports NHWC format but I think pytorch doesn't, so one of the way is to reshape it to <code>[N, Height, Width, channels]</code> and then iterate like :</p>
  
  <pre><code># if img is reshaped to [N, H, W, C]
  img
  # tensor of dimension [N, C]
  aud
  
  ans = torch.empty(N, H, W, dtype=torch.double)
  
  for batches in range(img.shape[0]):
      for i in range(img.shape[1]):
          for j in range(img.shape[2]):
              ans[batches][i][j] = torch.dot(img[batches][i][j], aud[batches])
  </code></pre>
  
  <p>Any other cleaner API ?</p>
  
  <p>PS : This step is required in DeepMind's paper "Object That Sound" for sound localization step.</p>