input: Write a function to create a k-means clustering algorithm in Python that performs clustering on a given dataset. The function should initialize centroids randomly, assign data points to the closest centroid, update centroids based on the mean of their assigned points, and repeat this process until the centroids converge. The function should return the clusters assigned to each data point and the final centroid positions. If the dataset is empty, the function should return empty clusters and centroids.
  
  assert kmeans(3, np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]])) == (np.array([0, 0, 1, 1, 2]), np.array([[2, 3], [6, 7], [9, 10]]))
  assert kmeans(2, np.array([[1, 2], [3, 4], [1, 2.5], [3.5, 4]])) == (np.array([0, 1, 0, 1]), np.array([[1, 2.25], [3.25, 4]]))
  assert kmeans(1, np.array([[1, 1], [2, 2], [3, 3]])) == (np.array([0, 0, 0]), np.array([[2, 2]]))
  assert kmeans(3, np.array([[1, 1], [4, 4], [2, 2], [5, 5]])) == (np.array([0, 2, 1, 2]), np.array([[1, 1], [4, 4], [3.5, 3.5]]))
  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