Re: [Tutor] fast sampling with replacement

2010-02-21 Thread Steven D'Aprano
On Sun, 21 Feb 2010 03:22:19 am Andrew Fithian wrote: > Hi tutor, > > I'm have a statistical bootstrapping script that is bottlenecking on > a python function sample_with_replacement(). I wrote this function > myself because I couldn't find a similar function in python's random > library. random.

Re: [Tutor] fast sampling with replacement

2010-02-21 Thread Dave Angel
Luke Paireepinart wrote: Can you explain what your function is doing and also post some test code to profile it? On Sat, Feb 20, 2010 at 10:22 AM, Andrew Fithian wrote: Hi tutor, I'm have a statistical bootstrapping script that is bottlenecking on a python function sample_with_replaceme

[Tutor] fast sampling with replacement

2010-02-21 Thread Andrew Fithian
On Sat, Feb 20, 2010 at 11:55 AM, Luke Paireepinart wrote: > > > On Sat, Feb 20, 2010 at 1:50 PM, Kent Johnson wrote: > >> On Sat, Feb 20, 2010 at 11:22 AM, Andrew Fithian >> wrote: >> > can >> > you help me speed it up even more? >> > import random >> > def sample_with_replacement(list): >> >

Re: [Tutor] fast sampling with replacement

2010-02-20 Thread Luke Paireepinart
On Sat, Feb 20, 2010 at 1:50 PM, Kent Johnson wrote: > On Sat, Feb 20, 2010 at 11:22 AM, Andrew Fithian > wrote: > > can > > you help me speed it up even more? > > import random > > def sample_with_replacement(list): > > l = len(list) # the sample needs to be as long as list > > r = xra

Re: [Tutor] fast sampling with replacement

2010-02-20 Thread Kent Johnson
On Sat, Feb 20, 2010 at 11:22 AM, Andrew Fithian wrote: > can > you help me speed it up even more? > import random > def sample_with_replacement(list): >     l = len(list) # the sample needs to be as long as list >     r = xrange(l) >     _random = random.random >     return [list[int(_random()*l

Re: [Tutor] fast sampling with replacement

2010-02-20 Thread Luke Paireepinart
Can you explain what your function is doing and also post some test code to profile it? On Sat, Feb 20, 2010 at 10:22 AM, Andrew Fithian wrote: > Hi tutor, > > I'm have a statistical bootstrapping script that is bottlenecking on a > python function sample_with_replacement(). I wrote this functio

[Tutor] fast sampling with replacement

2010-02-20 Thread Andrew Fithian
Hi tutor, I'm have a statistical bootstrapping script that is bottlenecking on a python function sample_with_replacement(). I wrote this function myself because I couldn't find a similar function in python's random library. This is the fastest version of the function I could come up with (I used c