Consider: I'm trying to generate s samples the von mises distribution for every element ofk, which raises an error for k=0 (which is my null hypothesis, so I want it as accurate as possible). I'm trying to "fudge" it by giving a low k and randomizing the bias direction.
Assume
import numpy as np
s = 1000
k = np.arange(10)
theta = np.zeros_like(k)
shp = (10,)
Then the following 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)
gives the error
Traceback (most recent call last):
File "<ipython-input-blah>", line 1, in <module>
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)
But . . . those shapes are the same. Why can't I do that?
EDIT: as pointed out below -
theta[:, k_zero] = np.random.rand(s, np.sum(k_zero)) * np.pi - np.pi / 2
works. Is this just a bug in the error message?