input: Write a function to implement a k-means clustering algorithm in Python that takes an integer `k` and a 2D array `data` as inputs. The function should return the cluster assignments and the final centroids after the algorithm converges. If the number of data points is less than `k`, raise a ValueError.
  assert kmeans(3, np.array([[1, 2], [2, 3], [3, 4], [8, 9], [9, 10], [10, 11]]))[0].tolist() in [[0, 0, 0, 1, 1, 1], [1, 1, 1, 0, 0, 0]]
  assert kmeans(2, np.array([[1, 2], [2, 3], [3, 4], [8, 9], [9, 10], [10, 11]]))[0].tolist() in [[0, 0, 0, 1, 1, 1], [1, 1, 1, 0, 0, 0]]
  try:
      kmeans(7, np.array([[1, 2], [2, 3], [3, 4], [8, 9], [9, 10], [10, 11]]))
      assert False
  except ValueError:
      assert True
  assert kmeans(1, np.array([[1, 2], [2, 3], [3, 4], [8, 9]]))[0].tolist() == [0, 0, 0, 0]
output: def kmeans(k, data):
      if len(data) < k:
          raise ValueError("Number of data points is less than k")
      
      def euclidean_distance(p1, p2):
          return np.linalg.norm(p1 - p2)
      
      def assign_clusters(data, centroids):
          clusters = [[] for _ in range(k)]
          for point in data:
              distances = [euclidean_distance(point, centroid) for centroid in centroids]
              cluster_idx = np.argmin(distances)
              clusters[cluster_idx].append(point)
          return clusters
      
      def update_centroids(clusters):
          return [np.mean(cluster, axis=0) for cluster in clusters]
      
      centroids = data[np.random.choice(len(data), k, replace=False)]
      while True:
          clusters = assign_clusters(data, centroids)
          new_centroids = update_centroids(clusters)
          if np.all(centroids == new_centroids):
              break
          centroids = new_centroids
      
      cluster_assignments = np.zeros(len(data), dtype=int)
      for i, cluster in enumerate(clusters):
          for point in cluster:
              cluster_assignments[np.where((data == point).all(axis=1))[0][0]] = i
      
      return cluster_assignments, centroids