title: Speeding up numpy small function
body: <p>This small function is called multiple times in an application and runs really slow compared to the same code implementation in Matlab. There it works maybe as much as 10-100 times faster in so I was wondering where can it be improved in python/numpy. </p>
  
  <pre><code>def ahamming(n,mid):
      data = np.zeros(n)
      wid1 = mid - 1
      wid2 = n - mid
      wid = max(wid1,wid2)
  
      for i in range(n):
          arg = (i+1) - mid;
          data[i] = np.cos((np.pi*arg)/wid);
      return 0.54 + 0.46*data
  </code></pre>