title: Is there a better way to broadcast arrays?
body: <p>I want to broadcast an array <code>b</code> to the shape it would take if it were in an arithmetic operation with another array <code>a</code>.</p>
  
  <p>For example, if <code>a.shape = (3,3)</code> and <code>b</code> was a scalar, I want to get an array whose shape is <code>(3,3)</code> and is filled with the scalar.</p>
  
  <p>One way to do this is like this:</p>
  
  <pre><code>&gt;&gt;&gt; import numpy as np
  &gt;&gt;&gt; a = np.arange(9).reshape((3,3))
  &gt;&gt;&gt; b = 1 + a*0
  &gt;&gt;&gt; b
  array([[1, 1, 1],
         [1, 1, 1],
         [1, 1, 1]])
  </code></pre>
  
  <p>Although this works practically, I can't help but feel it looks a bit weird, and wouldn't be obvious to someone else looking at the code what I was trying to do.</p>
  
  <p>Is there any more elegant way to do this? I've looked at the documentation for <code>np.broadcast</code>, but it's orders of magnitude slower.</p>
  
  <pre><code>In [1]: a = np.arange(10000).reshape((100,100))
  
  In [2]: %timeit 1 + a*0
  10000 loops, best of 3: 31.9 us per loop
  
  In [3]: %timeit bc = np.broadcast(a,1);np.fromiter((v for u, v in bc),float).reshape(bc.shape)
  100 loops, best of 3: 5.2 ms per loop
  
  In [4]: 5.2e-3/32e-6
  Out[4]: 162.5
  </code></pre>