title: Can numpy optimized code recieve significant increase in speed by rewriting it in Cython?
body: <p>I have some python code doing numerical computations on 2d and 3d numpy arrays. The code is optimized in the way that it is not using any for loops, only numpy operations. All operations are done on <code>float</code> types.</p>
  
  <p>These are the numpy operations used: <code>numpy.zeros</code>, <code>numpy.reshape</code>, <code>numpy.where</code>, <code>numpy.logical_or.reduce</code>, <code>numpy.put</code>, <code>numpy.add</code>, <code>numpy.subtract</code>, <code>numpy.true_devide</code>, <code>numpy.rint</code></p>
  
  <p>I ran some tests and the overhead lies within the <code>numpy.where</code>, <code>numpy.put</code> and <code>numpy.rint</code>operations.</p>
  
  <p>My question is, since I already optimized the code in the sense that it is only using numpy operations, if I can expect any significant speed-ups when rewriting my piece of code in Cython. Or might there be another option? Rest of the code is in Python and has to stay in Python. A significant increase would be an average increase in speed of about 20%.</p>
  
  <p><strong>EDIT1:</strong></p>
  
  <pre><code># &lt;im&gt; is a 2d floating point numpy array
  # &lt;w,h&gt; are the width and hight of &lt;im&gt;    
  
  pdt = np.rint(np.add(pix[:,None,:], np.multiply(depthValOfU[:,None], features[:,0]))).astype(int)
  d_two = np.zeros(2000*500)
  pdt = np.reshape(pdt, (2000*500, 2))
  np.put(d_two, np.where(np.logical_or.reduce((pdt[:,0] &lt; 0, pdt[:,0] &gt; w, pdt[:,1] &lt; 0, pdt[:,1] &gt; h))), self.const)
  zero_ind = np.where(d_two &lt; 1000)  
  np.put(d_two, zero_ind, im[pdt[zero_ind,0], pdt[zero_ind,1]])
  </code></pre>
  
  <p>It would be quite a lot of code I needed to provide to make this piece of code runnable but I hope this helps to make some sense of it.</p>