title: Better way to improve summing elements of complex matrix in Numpy over MATLAB
body: <p>I am trying to rewrite the MATLAB code below into Python, and found that my Python code (2.7 sec) is slower than MATLAB (1.2 sec).
  I have tried many different ways, including the module numba, but no luck yet.
  How can I make the Python code faster?</p>
  
  <h1>MATLAB code:</h1>
  
  <pre class="lang-matlab prettyprint-override"><code>szA=[1024,1280]; HfszA=[512,640];
  [aPx,aPy]=meshgrid(-HfszA(2):HfszA(2)-1,-HfszA(1):HfszA(1)-1);
  img=randi(255,1024,1280);
  fx=rand(); fy=rand();
  tic
  for i=1:20
      F=abs(sum(sum(img.*exp(-1i*2*pi*(fx*aPx+fy*aPy)))));
  end
  toc
  </code></pre>
  
  <h1>Python code:</h1>
  
  <pre><code>import numpy as np
  import time
  
  szA=[1024,1280]; HfszA=[512,640]
  aPx,aPy=np.meshgrid(np.arange(-HfszA[1],HfszA[1]),np.arange(-HfszA[0],HfszA[0]))
  img=np.array(np.random.randint(256,size=(1024,1280)))
  
  fx=np.random.rand()
  fy=np.random.rand()
  
  start = time.time()
  for i in range(20):
      F=abs(np.sum(img*np.exp(-1j*2*np.pi*(fx*aPx+fy*aPy))))
  end = time.time()
  print("Elapsed (after compilation) = %s" % (end - start))
  print(F)
  </code></pre>