code: def assign_labels(data, centroids, ncenters):
      from shogun import MulticlassLabels
      import shogun as sg
      from numpy import arange
  
      labels = MulticlassLabels(arange(0.0, ncenters))
      fea_centroids = sg.create_features(centroids)
      distance = sg.create_distance("EuclideanDistance")
      distance.init(fea_centroids, fea_centroids)
      knn = sg.create_machine(
          "KNN", k=1, distance=distance, labels=labels
      )
      knn.train()
      return knn.apply(data)
  
imports: import shogun
  from numpy import *
label_desc: Use image node_id 2 for calling a global function with example usage: assign_labels(data, centroids, ncenters) and returns: knn