input: def kmeans(k, data):
      """
      Perform k-means clustering on data
      >>> kmeans(2, np.array([[1, 2], [2, 3], [10, 12], [11, 13]]))
      (array([0., 0., 1., 1.]), array([[ 1.5,  2.5],
                                        [10.5, 12.5]]))
      """
output:     import numpy as np
      
      def initialize_centroids(k, data):
          return data[np.random.choice(data.shape[0], k, replace=False)]
      
      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)
      
      while True:
          old_centroids = centroids
          centroids = update_centroids(data, labels, k)
          if has_converged(old_centroids, centroids):
              break
          labels = assign_clusters(data, centroids)
      
      return labels, centroids