April 5, 2006
6:33 a.m.
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