def sample_from_mixture(x, pred_weights, pred_means, pred_std, amount):
 samples = np.zeros((amount, 2))
 n_mix = len(pred_weights[0])
 to_choose_from = np.arange(n_mix)
 for (j, (weights, means, std_devs)) in enumerate(zip(pred_weights, pred_means, pred_std)):
  index = np.random.choice(to_choose_from, p=weights)
  samples[(j, 1)] = np.random.normal(means[index], std_devs[index], size=1)
  samples[(j, 0)] = x[j]
  if (j == (amount - 1)):
   break
 return samples

def sample_from_mixture ( x , pred_weights , pred_means , pred_std , amount ) : samples = np . zeros ( ( amount , 2 ) ) n_mix = len ( pred_weights [ 0 ] ) to_choose_from = np . arange ( n_mix ) for ( j , ( weights , means , std_devs ) ) in enumerate ( zip ( pred_weights , pred_means , pred_std ) ) : index = np . random . choice ( to_choose_from , p = weights ) samples [ ( j , 1 ) ] = np . random . normal ( means [ index ] , std_devs [ index ] , size = 1 ) samples [ ( j , 0 ) ] = x [ j ] if ( j == ( amount - 1 ) ) : break return samples
draws samples from mixture model .