input: Write a function to create a k-means clustering algorithm in Python that performs clustering on data. The function should return the clusters and the centroids. If the input data is empty, the function should return empty clusters and centroids.
  import numpy as np 
  
  def kmeans(k, data): 
      """
      Perform k-means clustering on data
      """
      if len(data) == 0:
          return np.array([]), np.array([])
  
      # randomly set initial centroids
      centroids = data[np.random.randint(low=0, high=len(data), size=k)]
      prev_centroids = np.zeros(centroids.shape)
  
      clusters = np.zeros(len(data))
      distances = np.zeros((len(data), k))
      
      # find the closest centroid for each sample
      while not np.allclose(centroids, prev_centroids):
          # save old centroids
          prev_centroids = centroids
      
          # get the distance between each point and each centroid
          for idx, centroid in enumerate(centroids):
              distances[:, idx] = np.linalg.norm(data - centroid, axis=1)
      
          # assign each sample to the closest centroids
          clusters = np.argmin(distances, axis=1)
      
          # update centroids 
          for idx in range(k):
              centroids[idx] = np.mean(data[clusters == idx], axis=0)
      
      return clusters, centroids
  
  assert np.array_equal(kmeans(2, np.array([[1, 2], [4, 5], [3, 4], [5, 6]])), ([0, 1, 1, 1], [[1, 2], [4.3333, 5]]))
  assert np.array_equal(kmeans(3, np.array([[1, 2], [5, 6], [2, 3], [5, 5], [2, 4]])), ([0, 2, 0, 1, 0], [[1.6667, 2.6667], [5, 5.5], [2, 3]]))
  assert np.array_equal(kmeans(1, np.array([[1, 2], [3, 4], [5, 6]])), ([0, 0, 0], [[3, 4]]))
  assert np.array_equal(kmeans(0, np.array([])), (np.array([]), np.array([])))
output: def kmeans(k, data): 
      if len(data) == 0:
          return np.array([]), np.array([])
  
      centroids = data[np.random.randint(low=0, high=len(data), size=k)]
      prev_centroids = np.zeros(centroids.shape)
  
      clusters = np.zeros(len(data))
      distances = np.zeros((len(data), k))
      
      while not np.allclose(centroids, prev_centroids):
          prev_centroids = centroids
      
          for idx, centroid in enumerate(centroids):
              distances[:, idx] = np.linalg.norm(data - centroid, axis=1)
      
          clusters = np.argmin(distances, axis=1)
      
          for idx in range(k):
              centroids[idx] = np.mean(data[clusters == idx], axis=0)
      
      return clusters, centroids