input: Write a function to implement a k-means clustering algorithm in Python, which accepts an integer 'k' and a NumPy array 'data' as input. The function should return the clusters and the final centroids after the iterative process.
  assert kmeans(3, np.array([[1, 2], [2, 3], [3, 4], [10, 20], [11, 21], [12, 22]]))==(np.array([0, 0, 0, 1, 1, 1]), np.array([[2., 3.], [11., 21.]]))
  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(1, np.array([[1, 1], [2, 2], [3, 3], [4, 4]]))==(np.array([0, 0, 0, 0]), np.array([[2.5, 2.5]]))
  assert kmeans(4, np.array([[1, 1], [2, 2], [3, 3], [4, 4]]))==(np.array([0, 1, 2, 3]), np.array([[1, 1], [2, 2], [3, 3], [4, 4]]))
  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