title: numpy.dot - ensuring matrix compatibility?
body: <p>I've got a 2D array <code>X</code>.</p>
  
  <p><code>X[i]</code> is a 1D array with 3 values.
  Its shape is: <code>(3L,)</code></p>
  
  <p>I then have a 3D array, <code>g</code>, which is 2x3x2.
  If I print out the shape of <code>g[j]</code>, it is: <code>(3L,2L)</code> and the shape of <code>g[j][i]</code> is <code>(2L,)</code></p>
  
  <p>Now I'm running a loop like this:</p>
  
  <pre><code>for j in range(len(g)):
              for i in range(no_samples):
              e = math.exp(1. + np.dot(X[i], g[j][i]) - np.dot(X[i],g[i_class][i]))
  </code></pre>
  
  <p>But I get the following error:</p>
  
  <pre><code>  e = math.exp(1. + np.dot(X[i], g[j][i]) - np.dot(X[i],g[i_class][i]))
  ValueError: matrices are not aligned
  </code></pre>
  
  <p>I guess I understand the problem, but don't know how to fix it. I tried transposing <code>g[j][i]</code> but it didn't make a difference. I tried reshaping <code>X[i]</code> to force it to be <code>(3L,1L)</code>. I thought that if <code>X[i]</code> is 3x1 and <code>g[j][i]</code> is 1x2, then the matrices are compatible and I should be able to use <code>np.dot</code>. But I think I must be missing something.</p>
  
  <p>What's the correct way to do this?</p>