input: Write a function to implement a k-means clustering algorithm in Python. The function should take as input the number of clusters \( k \) and the data to be clustered. The function should return the assigned clusters and the final centroids.
  
  assert kmeans(2, np.array([[1, 1], [2, 2], [9, 9], [10, 10]])) == (np.array([0, 0, 1, 1]), np.array([[1.5, 1.5], [9.5, 9.5]]))
  assert kmeans(3, np.array([[1, 1], [2, 2], [3, 3], [9, 9], [10, 10], [11, 11]])) == (np.array([0, 0, 0, 1, 1, 1]), np.array([[2, 2], [10, 10], [11, 11]]))
  assert kmeans(4, np.array([[1, 1], [5, 5], [8, 8], [12, 12], [15, 15], [20, 20]])) == (np.array([0, 1, 2, 3, 3, 3]), np.array([[1, 1], [5, 5], [8, 8], [15.66666667, 15.66666667]]))
  assert kmeans(2, np.array([])) == (np.array([]), np.array([]))
output: 
  def kmeans(k, data):
      if len(data) == 0:
          return np.array([]), np.array([])
      
      centroids = data[np.random.choice(data.shape[0], k, replace=False)]
      while True:
          distances = np.linalg.norm(data[:, np.newaxis] - centroids, axis=2)
          clusters = np.argmin(distances, axis=1)
          new_centroids = np.array([data[clusters == i].mean(axis=0) for i in range(k)])
          
          if np.all(centroids == new_centroids):
              break
          centroids = new_centroids
      
      return clusters, centroids
  