title: shape mismatch: value array of shape X could not be broadcast to indexing result of shape . . . X?
body: <p>Consider: I'm trying to generate <code>s</code> samples the von mises distribution for every element of<code>k</code>, which raises an error for <code>k=0</code> (which is my null hypothesis, so I want it as accurate as possible).  I'm trying to "fudge" it by giving a low <code>k</code> and randomizing the bias direction.</p>
  
  <p>Assume</p>
  
  <pre><code>import numpy as np
  s = 1000
  k = np.arange(10)
  theta = np.zeros_like(k)
  shp = (10,)
  </code></pre>
  
  <p>Then the following code</p>
  
  <pre><code>import scipy.stats as stat    
  rpt = (s,) + tuple(np.ones_like(shp))
  theta = np.tile(theta, rpt)
  k_zero = np.logical_not(k)
  theta[:, k_zero] = np.random.rand(np.sum(k_zero), s) * 2 * np.pi - np.pi
  k[k_zero] = .001
  ks = np.tile(k, rpt)    
  </code></pre>
  
  <p>gives the error</p>
  
  <pre><code>Traceback (most recent call last):
  
    File "&lt;ipython-input-blah&gt;", line 1, in &lt;module&gt;
      theta[:, k_zero] = np.random.rand(np.sum(k_zero), s) * np.pi - np.pi / 2
  
  ValueError: shape mismatch: value array of shape (1,1000) could not be broadcast to indexing result of shape (1,1000)
  </code></pre>
  
  <p>But  . . . those shapes are the same.  Why can't I do that?</p>
  
  <p><strong>EDIT:</strong> as pointed out below -</p>
  
  <pre><code>theta[:, k_zero] = np.random.rand(s, np.sum(k_zero)) * np.pi - np.pi / 2
  </code></pre>
  
  <p>works.  Is this just a bug in the error message?</p>