def step_expectation(X,n_components,means,variances): """E Step Parameters ---------- X : array-like, shape (n_samples,) The data. n_components : int The number of clusters means : array-like, shape (n_components,) The means of each mixture component. variances : array-like, shape (n_components,) The variances of each mixture component. Returns ------- weights : array-like, shape (n_components,n_samples) """ weights = np.zeros((n_components,len(X))) for j in range(n_components): weights[j,:] = norm(loc=means[j],scale=np.sqrt(variances[j])).pdf(X) return weights