title: Why the performance difference between numpy.zeros and numpy.zeros_like?
body: <p>I finally found a performance bottleneck in my code but am confused as to what the reason is. To solve it I changed all my calls of <code>numpy.zeros_like</code> to instead use <code>numpy.zeros</code>. But why is <code>zeros_like</code> sooooo much slower?</p>
  
  <p>For example (note <code>e-05</code> on the <code>zeros</code> call): </p>
  
  <pre><code>&gt;&gt;&gt; timeit.timeit('np.zeros((12488, 7588, 3), np.uint8)', 'import numpy as np', number = 10)
  5.2928924560546875e-05
  &gt;&gt;&gt; timeit.timeit('np.zeros_like(x)', 'import numpy as np; x = np.zeros((12488, 7588, 3), np.uint8)', number = 10)
  1.4402990341186523
  </code></pre>
  
  <p>But then strangely writing to an array created with <code>zeros</code> is noticeably slower than an array created with <code>zeros_like</code>:</p>
  
  <pre><code>&gt;&gt;&gt; timeit.timeit('x[100:-100, 100:-100] = 1', 'import numpy as np; x = np.zeros((12488, 7588, 3), np.uint8)', number = 10)
  0.4310588836669922
  &gt;&gt;&gt; timeit.timeit('x[100:-100, 100:-100] = 1', 'import numpy as np; x = np.zeros_like(np.zeros((12488, 7588, 3), np.uint8))', number = 10)
  0.33325695991516113
  </code></pre>
  
  <p>My guess is <code>zeros</code> is using some CPU trick and not actually writing to the memory to allocate it. This is done on the fly when it's written to. But that still doesn't explain the massive discrepancy in array creation times.</p>
  
  <p>I'm running Mac OS X Yosemite with the current numpy version: </p>
  
  <pre><code>&gt;&gt;&gt; numpy.__version__
  '1.9.1'
  </code></pre>