def categorical_sample(prob_n, np_random):
 prob_n = np.asarray(prob_n)
 csprob_n = np.cumsum(prob_n)
 return (csprob_n > np_random.rand()).argmax()

def categorical_sample ( prob_n , np_random ) : prob_n = np . asarray ( prob_n ) csprob_n = np . cumsum ( prob_n ) return ( csprob_n > np_random . rand ( ) ) . argmax ( )
sample from categorical distribution each row specifies class probabilities .