title: NumPy ndarray broadcasting - shape (X,) vs (X, 1) to operate with (X,Y)
body: <p>I have a NumPy <code>ndarray</code> which is shaped (32, 1024) and holds 32 signal measurements which I would like to combine into a single 1024 element long array, with a different weight for each of the 32. I was using <code>numpy.average</code> but my weights are complex and <code>average</code> performs a normalisation of the weights based on the sum which throws off my results.</p>
  
  <p>Looking at the code for average I realised that I can accomplish the same thing by multiplying the weights by the signal array and then summing over the first axis. However when I try and multiply my (32,) weights array by the (32, 1024) signal array I get a dimension mismatch as the (32,) cannot be broadcast to (32, 1024). If I reshape the weights array to (32, 1) then everything works as expected, however this results in rather ugly code:</p>
  
  <pre><code>avg = (weights.reshape((32, 1)) * data).sum(axis=0)
  </code></pre>
  
  <p>Can anybody explain why NumPy will not allow my (32,) array to broadcast to (32, 1024) and/or suggest an alternative, neater way of performing the weighted average?</p>