[Numpy-discussion] A random.normal function with stdev as array
Eric Emsellem
emsellem at obs.univ-lyon1.fr
Wed Apr 5 06:33:23 CDT 2006
Hi,
I am trying to optimize a code where I derive random numbers many times
and having an array of values for the stdev parameter.
I wish to have an efficient way of doing something like:
##################
stdev = array([1.1,1.2,1.0,2.2])
result = numpy.zeros(stdev.shape, Float)
for i in range(len(stdev)) :
result[i] = numpy.random.normal(0, stdev[i])
##################
In my case, stdev can in fact be an array of a few millions floats...
so I really need to optimize things.
Any hint on how to code this efficiently ?
And in general, where could I find tips for optimizing a code where I
unfortunately have too many loops such as "for i in range(Nbody) : "
with Nbody being > 10^6 ?
thanks!
Eric
More information about the Numpy-discussion
mailing list