nonuniform sampling with replacement

Alf P. Steinbach alfps at
Sun Mar 21 13:28:15 CET 2010

* Alf P. Steinbach:
> * Jah_Alarm:
>> I've got a vector length n of integers (some of them are repeating),
>> and I got a selection probability vector of the same length. How will
>> I sample with replacement k (<=n) values with the probabilty vector.
>> In Matlab this function is randsample. I couldn't find anything to
>> this extent in Scipy or Numpy.
> <code>
> </code>
> Disclaimer: I just cooked it up and just cooked up binary searches 
> usually have bugs. They usually need to be exercised and fixed. But I 
> think you get the idea. Note also that division differs in Py3 and Py2. 
> This is coded for Py3.

Sorry, I realized this just now: the name "p" in the choice() method is utterly 
misleading, which you can see from the call; it's a random number not a 
probability. I guess my fingers just repeated what they typed earlier.


- Alf (repeat typist)

More information about the Python-list mailing list