title: How to sample from a log-probability distribution?
body: <p>I have some code that uses log-probability. When I want to draw a sample from the probability distribution, I use</p>
  
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  
  probs = np.exp(logprobs)
  probs /= probs.sum()
  sample = np.random.choice(X, p=probs, size=1)[0]
  </code></pre>
  
  <p>But there is some overhead here in the exponentiation and division. And the numpy <code>random.choice</code> function requires the probabilities are between 0 and 1, and sum to 1.</p>
  
  <p>Are there any fast techniques for me to draw a sample using the nonnormalized log-probability array? I only ever need one sample at a time, and the frequency of drawing it just needs to be proportional to the log-probability.</p>