[Numpy-discussion] A random.normal function with stdev as array
John Byrnes
byrnes at bu.edu
Wed Apr 5 08:58:21 CDT 2006
Hi Eric,
In the past , I've done things like
######
normdist = lambda x: numpy.random.normal(0,x)
vecnormal = numpy.vectorize(normdist)
stdev = numpy.array([1.1,1.2,1.0,2.2])
result = vecnormal(stdev)
######
This works fine for up to 10k elements for stdev for some reason.
Any larger then that and i get a Bus error on my PPC mac and a segfault on
my x86 linux box.
I'm running numpy 0.9.7.2325 on both machines.
Perhaps for larger inputs, you could break up your loop into smaller
vectorized chunks.
Regards,
John
On Wed, Apr 05, 2006 at 03:32:06PM +0200, Eric Emsellem wrote:
> 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
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting language
> that extends applications into web and mobile media. Attend the live webcast
> and join the prime developer group breaking into this new coding territory!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
--
If liberty and equality, as is thought by some are chiefly to be found in democracy,
they will be best attained when all persons alike share in the government to the utmost.
-- Aristotle, Politics
More information about the Numpy-discussion
mailing list