def mv_mixture_rvs(prob, size, dist, nvars, **kwargs):
 if (len(prob) != len(dist)):
  raise ValueError('You must provide as many probabilities as distributions')
 if (not np.allclose(np.sum(prob), 1)):
  raise ValueError('prob does not sum to 1')
 if (kwargs is None):
  kwargs = (({},) * len(prob))
 idx = _make_index(prob, size)
 sample = np.empty((size, nvars))
 for i in range(len(prob)):
  sample_idx = idx[..., i]
  sample_size = sample_idx.sum()
  sample[sample_idx] = dist[i].rvs(size=int(sample_size))
 return sample

def mv_mixture_rvs ( prob , size , dist , nvars , ** kwargs ) : if ( len ( prob ) != len ( dist ) ) : raise ValueError ( 'You must provide as many probabilities as distributions' ) if ( not np . allclose ( np . sum ( prob ) , 1 ) ) : raise ValueError ( 'prob does not sum to 1' ) if ( kwargs is None ) : kwargs = ( ( { } , ) * len ( prob ) ) idx = _make_index ( prob , size ) sample = np . empty ( ( size , nvars ) ) for i in range ( len ( prob ) ) : sample_idx = idx [ ... , i ] sample_size = sample_idx . sum ( ) sample [ sample_idx ] = dist [ i ] . rvs ( size = int ( sample_size ) ) return sample
sample from a mixture of multivariate distributions .