title: Weighted random sample without replacement in python
body: <p>I need to obtain a <em>k-sized</em> sample without replacement from a population, where each member of the population has a associated weight (W).</p>
  
  <p>Numpy's <em>random.choices</em> will not perform this task without replacement, and <em>random.sample</em> won't take a weighted input. </p>
  
  <p>Currently, this is what I am using:</p>
  
  <pre><code>P = np.zeros((1,Parent_number))
  n=0
  while n &lt; Parent_number:
      draw = random.choices(population,weights=W,k=1)
      if draw not in P:
          P[0,n] = draw[0]
          n=n+1
  P=np.asarray(sorted(P[0])) 
  </code></pre>
  
  <p>While this works, it reqires switching back and forth from arrays, to lists and back to arrays and is, therefore, less than ideal.</p>
  
  <p>I am looking for the simplest and easiest to understand solution as this code will be shared with others.</p>