On Mon, Dec 20, 2010 at 10:28, Alan G Isaac wrote:
> I want to sample *without* replacement from a vector
> (as with Python's random.sample). I don't see a direct
> replacement for this, and I don't want to carry two
> PRNG's around. Is the best way something like this?
>
> permutation(m
We often need to generate more than one such sample from an array, e.g.
for permutation tests. If we shuffle an array x of size N and use x[:M] as
a random sample "without replacement", we just need to put them back
randomly to get the next sample (cf. Fisher-Yates shuffle). That way we
get O(M) a
I know this question came up on the mailing list some time ago
(19/09/2008), and the conclusion was that yes, you can do it more or
less efficiently in pure python; the trick is to use two different
methods. If your sample is more than, say, a quarter the size of the
set you're drawing from, you pe
On 12/20/2010 10:49 PM, josef.p...@gmail.com wrote:
> What's the difference between a numpy Random and a python
> random.Random instance of separate states of the random number
> generators?
Sorry, I don't understand the question. The difference
for my use is that a np.RandomState instance provi
On Mon, Dec 20, 2010 at 10:19 PM, Alan G Isaac wrote:
> On 12/20/2010 9:41 PM, josef.p...@gmail.com wrote:
>> python has it in random
>>
>> sample( population, k)
>
>
> Yes, I mentioned this in my original post:
> http://www.mail-archive.com/numpy-discussion@scipy.org/msg29324.html
>
> But good si
On 12/20/2010 9:41 PM, josef.p...@gmail.com wrote:
> python has it in random
>
> sample( population, k)
Yes, I mentioned this in my original post:
http://www.mail-archive.com/numpy-discussion@scipy.org/msg29324.html
But good simulation practice is perhaps to seed
a simulation specific random num
On Mon, Dec 20, 2010 at 11:28 AM, Alan G Isaac wrote:
> I want to sample *without* replacement from a vector
> (as with Python's random.sample). I don't see a direct
> replacement for this, and I don't want to carry two
> PRNG's around. Is the best way something like this?
>
> permutatio
I think this is not possible to do efficiently with just numpy. If you want
to do this efficiently, I wrote a no-replacement sampler in Cython some time
ago (below). I hearby release it to the public domain.
'''
Created on Oct 24, 2009
http://stackoverflow.com/questions/311703/algorithm-for-sampl
I want to sample *without* replacement from a vector
(as with Python's random.sample). I don't see a direct
replacement for this, and I don't want to carry two
PRNG's around. Is the best way something like this?
permutation(myvector)[:samplesize]
Thanks,
Alan Isaac