Edit: y = np.ravel(y) in the last line.