title: Optimizing Many Matrix Operations in Python / Numpy
body: <p>In writing some numerical analysis code, I have bottle-necked at a function that requires many Numpy calls. I am not entirely sure how to approach further performance optimization.</p>
  
  <p>Problem:</p>
  
  <p>The function determines error by calculating the following, </p>
  
  <p><a href="https://i.stack.imgur.com/gh1Es.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gh1Es.png" alt="Error function"></a></p>
  
  <p>Code:</p>
  
  <pre><code>def foo(B_Mat, A_Mat):
      Temp = np.absolute(B_Mat)
      Temp /= np.amax(Temp)
      return np.sqrt(np.sum(np.absolute(A_Mat - Temp*Temp))) / B_Mat.shape[0]
  </code></pre>
  
  <p>What would be the best way to squeeze some extra performance out of the code? Would my best course of action be performing the majority of the operations in a single for loop with Cython to cut down on the temporary arrays?</p>