code: def _labels_cost(X, centroids, dissim, membship=None):
      
  
      X = check_array(X)
  
      n_points = X.shape[0]
      cost = 0.
      labels = np.empty(n_points, dtype=np.uint16)
      for ipoint, curpoint in enumerate(X):
          diss = dissim(centroids, curpoint, X=X, membship=membship)
          clust = np.argmin(diss)
          labels[ipoint] = clust
          cost += diss[clust]
  
      return labels, cost
docs: Calculate labels and cost function given a matrix of points and
      a list of centroids for the k-modes algorithm.