code: def k_means(points, k, **kwargs):
      
      from scipy.cluster.vq import kmeans
      from scipy.spatial import cKDTree
  
      points = np.asanyarray(points, dtype=np.float64)
      points_std = points.std(axis=0)
      whitened = points / points_std
      centroids_whitened, distortion = kmeans(whitened, k, **kwargs)
      centroids = centroids_whitened * points_std
  
      # find which centroid each point is closest to
      tree = cKDTree(centroids)
      labels = tree.query(points, k=1)[1]
  
      return centroids, labels
docs: Find k centroids that attempt to minimize the k- means problem:
      https://en.wikipedia.org/wiki/Metric_k-center
  
      Parameters
      ----------
      points:  (n, d) float
          Points in a space
      k : int
           Number of centroids to compute
      **kwargs : dict
          Passed directly to scipy.cluster.vq.kmeans
  
      Returns
      ----------
      centroids : (k, d) float
           Points in some space
      labels: (n) int
          Indexes for which points belong to which centroid