input: def kmeans(k, data):
      """
      Perform k-means clustering on data
      >>> kmeans(2, np.array([[1, 1], [2, 2], [4, 4], [5, 5]]))
      (array([0., 0., 1., 1.]), array([[1.5, 1.5],
                                      [4.5, 4.5]]))
      >>> kmeans(3, np.array([[1, 1], [2, 2], [4, 4], [5, 5], [9, 9]]))
      (array([0., 0., 1., 1., 2.]), array([[1.5, 1.5],
                                          [4.5, 4.5],
                                          [9., 9.]]))
      """
output:     import numpy as np
  
      def initialize_centroids(k, data):
          indices = np.random.choice(len(data), k, replace=False)
          return data[indices]
  
      def assign_clusters(data, centroids):
          distances = np.linalg.norm(data[:, np.newaxis] - centroids, axis=2)
          return np.argmin(distances, axis=1)
  
      def update_centroids(data, labels, k):
          new_centroids = np.zeros((k, data.shape[1]))
          for i in range(k):
              new_centroids[i] = np.mean(data[labels == i], axis=0)
          return new_centroids
  
      def has_converged(old_centroids, new_centroids, tol=1e-4):
          return np.all(np.linalg.norm(old_centroids - new_centroids, axis=1) < tol)
  
      centroids = initialize_centroids(k, data)
      labels = assign_clusters(data, centroids)
      old_centroids = np.zeros_like(centroids)
  
      while not has_converged(old_centroids, centroids):
          old_centroids = centroids
          labels = assign_clusters(data, centroids)
          centroids = update_centroids(data, labels, k)
  
      return labels, centroids