[Numpy-discussion] in place random generation
Charles R Harris
Thu Mar 8 12:46:14 CST 2007
On 3/8/07, Robert Kern <firstname.lastname@example.org> wrote:
> Daniel Mahler wrote:
> > On 3/8/07, Charles R Harris <email@example.com> wrote:
> >> Robert thought this might relate to Travis' changes adding broadcasting
> >> the random number generator. It does seem certain that generating small
> >> arrays of random numbers has a very high overhead.
> > Does that mean someone is working on fixing this?
> It's not on the top of my list, no.
> > Also what does 'adding broadcasting to the number generator' mean?
> normal([[0.0], [0.5]], [1.0, 2.0, 3.0])
> That gives you a (2, 3) array of random numbers drawn from 6 different
> distributions: [[(mean=0, stdev=1), (mean=0, stdev=2), (mean=0, stdev=3)],
> [(mean=0.5, stdev=1), (mean=0.5, stdev=2), (mean=0.5,
For normals this seems overkill as the same result can be achieved by an
offset and scale, i.e., if r is an array of random numbers with mean 0 and
sigma 1, then
myrandomarray = (r*mysigma + mymean)
easily achieves the same result. Other distributions don't have such happy
properties, unfortunately, and will have high overhead regardless. For
instance, Poisson distributions require a computation of new internal
parameters for each value of the mean and doing this on an item by item
basis over a whole array is a terrible idea. Hmm, I am not convinced that
broadcasting is going to buy you much except overhead. Perhaps this problem
should be approached on a case by case basis rather than by some global
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion