title: Speeding up multinomial random sample in Python/NumPy
body: <p>I'm generating a vector of draws from a multinomial distribution over a set of probabilities <code>probs</code>, where each draw is the index of the entry in <code>probs</code> that was chosen:</p>
  
  <pre><code>import numpy as np
  def sample_mult(K, probs):
      result = np.zeros(num_draws, dtype=np.int32)
      for n in xrange(K):
          draws = np.random.multinomial(1, probs)
          result[n] = np.where(draws == 1)[0][0]
      return result
  </code></pre>
  
  <p>Can this be sped up? It seems inefficient to call <code>np.random.multinomial</code> over and over again (and <code>np.where</code> might also be slow.)</p>
  
  <p><code>timeit</code> says <code>The slowest run took 6.72 times longer than the fastest. This could mean that an intermediate result is being cached 
  100000 loops, best of 3: 18.9 µs per loop</code></p>