title: Why does matrix multiplication give different results depending on how they are grouped?
body: <p>We know that <code>A*B*C = A*(B*C)</code>, but why this matrix multiplication got different result?</p>
  
  <pre><code>import numpy as np
  
  A = np.array([[1,2,3],[4,5,6]])
  
  B = np.array([[1,2,3],[4,5,6],[7,8,9]])
  
  print( A.dot( np.linalg.inv(B) ).dot(A.T) )
  
  print( A.dot( np.linalg.inv(B).dot(A.T) ) )
  </code></pre>
  
  <p>The result is</p>
  
  <pre><code>[[ 0.5  2. ]
   [ 1.   4. ]]
  </code></pre>
  
  <p>and</p>
  
  <pre><code>[[  2.   4.]
   [  8.  16.]]
  </code></pre>