class_docstr: !
  @brief Class represents clustering algorithm K-Medians.
  @details The algorithm is less sensitive to outliers than K-Means. Medians are calculated instead of centroids.
  
  Example:
  @code
      from pyclustering.cluster.kmedians import kmedians
      from pyclustering.cluster import cluster_visualizer
      from pyclustering.utils import read_sample
      from pyclustering.samples.definitions import FCPS_SAMPLES
  
      # Load list of points for cluster analysis.
      sample = read_sample(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS)
  
      # Create instance of K-Medians algorithm.
      initial_medians = [[0.0, 0.1], [2.5, 0.7]]
      kmedians_instance = kmedians(sample, initial_medians)
  
      # Run cluster analysis and obtain results.
      kmedians_instance.process()
      clusters = kmedians_instance.get_clusters()
      medians = kmedians_instance.get_medians()
  
      # Visualize clustering results.
      visualizer = cluster_visualizer()
      visualizer.append_clusters(clusters, sample)
      visualizer.append_cluster(initial_medians, marker='*', markersize=10)
      visualizer.append_cluster(medians, marker='*', markersize=10)
      visualizer.show()
  @endcode
class_docstr_tok: ["!","@","brief","Class","represents","clustering","algorithm","K-Medians",".","@","details","The","algorithm","is","less","sensitive","to","outliers","than","K-Means",".","Medians","are","calculated","instead","of","centroids",".","Example",":","@","code","from","pyclustering.cluster.kmedians","import","kmedians","from","pyclustering.cluster","import","cluster_visualizer","from","pyclustering.utils","import","read_sample","from","pyclustering.samples.definitions","import","FCPS_SAMPLES","#","Load","list","of","points","for","cluster","analysis",".","sample","=","read_sample","(","FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS",")","#","Create","instance","of","K-Medians","algorithm",".","initial_medians","=","[","[","0.0",",","0.1","]",",","[","2.5",",","0.7","]","]","kmedians_instance","=","kmedians","(","sample",",","initial_medians",")","#","Run","cluster","analysis","and","obtain","results",".","kmedians_instance.process","(",")","clusters","=","kmedians_instance.get_clusters","(",")","medians","=","kmedians_instance.get_medians","(",")","#","Visualize","clustering","results",".","visualizer","=","cluster_visualizer","(",")","visualizer.append_clusters","(","clusters",",","sample",")","visualizer.append_cluster","(","initial_medians",",","marker=","'","*","'",",","markersize=10",")","visualizer.append_cluster","(","medians",",","marker=","'","*","'",",","markersize=10",")","visualizer.show","(",")","@","endcode"]
docstr: !
  @brief Calculates the closest cluster to each point.
  
  @param[in] points (array_like): Points for which closest clusters are calculated.
  
  @return (list) List of closest clusters for each point. Each cluster is denoted by index. Return empty
           collection if 'process()' method was not called.
  
  An example how to calculate (or predict) the closest cluster to specified points.
  @code
      from pyclustering.cluster.kmedians import kmedians
      from pyclustering.samples.definitions import SIMPLE_SAMPLES
      from pyclustering.utils import read_sample
  
      # Load list of points for cluster analysis.
      sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3)
  
      # Initial centers for sample 'Simple3'.
      initial_medians = [[0.2, 0.1], [4.0, 1.0], [2.0, 2.0], [2.3, 3.9]]
  
      # Create instance of K-Medians algorithm with prepared centers.
      kmedians_instance = kmedians(sample, initial_medians)
  
      # Run cluster analysis.
      kmedians_instance.process()
  
      # Calculate the closest cluster to following two points.
      points = [[0.25, 0.2], [2.5, 4.0]]
      closest_clusters = kmedians_instance.predict(points)
      print(closest_clusters)
  @endcode
docstr_tok: ["!","@","brief","Calculates","the","closest","cluster","to","each","point",".","@","param","[","in","]","points","(","array_like",")",":","Points","for","which","closest","clusters","are","calculated",".","@","return","(","list",")","List","of","closest","clusters","for","each","point",".","Each","cluster","is","denoted","by","index",".","Return","empty","collection","if","'process","(",")","'","method","was","not","called",".","An","example","how","to","calculate","(","or","predict",")","the","closest","cluster","to","specified","points",".","@","code","from","pyclustering.cluster.kmedians","import","kmedians","from","pyclustering.samples.definitions","import","SIMPLE_SAMPLES","from","pyclustering.utils","import","read_sample","#","Load","list","of","points","for","cluster","analysis",".","sample","=","read_sample","(","SIMPLE_SAMPLES.SAMPLE_SIMPLE3",")","#","Initial","centers","for","sample","'Simple3","'",".","initial_medians","=","[","[","0.2",",","0.1","]",",","[","4.0",",","1.0","]",",","[","2.0",",","2.0","]",",","[","2.3",",","3.9","]","]","#","Create","instance","of","K-Medians","algorithm","with","prepared","centers",".","kmedians_instance","=","kmedians","(","sample",",","initial_medians",")","#","Run","cluster","analysis",".","kmedians_instance.process","(",")","#","Calculate","the","closest","cluster","to","following","two","points",".","points","=","[","[","0.25",",","0.2","]",",","[","2.5",",","4.0","]","]","closest_clusters","=","kmedians_instance.predict","(","points",")","print","(","closest_clusters",")","@","endcode"]
code: def predict(self, points):
      """!
      @brief Calculates the closest cluster to each point.
  
      @param[in] points (array_like): Points for which closest clusters are calculated.
  
      @return (list) List of closest clusters for each point. Each cluster is denoted by index. Return empty
               collection if 'process()' method was not called.
  
      An example how to calculate (or predict) the closest cluster to specified points.
      @code
          from pyclustering.cluster.kmedians import kmedians
          from pyclustering.samples.definitions import SIMPLE_SAMPLES
          from pyclustering.utils import read_sample
  
          # Load list of points for cluster analysis.
          sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3)
  
          # Initial centers for sample 'Simple3'.
          initial_medians = [[0.2, 0.1], [4.0, 1.0], [2.0, 2.0], [2.3, 3.9]]
  
          # Create instance of K-Medians algorithm with prepared centers.
          kmedians_instance = kmedians(sample, initial_medians)
  
          # Run cluster analysis.
          kmedians_instance.process()
  
          # Calculate the closest cluster to following two points.
          points = [[0.25, 0.2], [2.5, 4.0]]
          closest_clusters = kmedians_instance.predict(points)
          print(closest_clusters)
      @endcode
  
      """
  
      if len(self.__clusters) == 0:
          return []
  
      differences = numpy.zeros((len(points), len(self.__medians)))
      for index_point in range(len(points)):
          differences[index_point] = [
              self.__metric(points[index_point], center)
              for center in self.__medians
          ]
  
      return numpy.argmin(differences, axis=1)
  
file_path: pyclustering/pyclustering/cluster/kmedians.py
imports: import math
  import numpy
  from pyclustering.cluster.encoder import type_encoding
  from pyclustering.utils.metric import distance_metric, type_metric
  import pyclustering.core.kmedians_wrapper
  from pyclustering.core.wrapper import ccore_library
  from pyclustering.core.metric_wrapper import metric_wrapper
label_desc: Use image node_id 3 for calling the kmedians obj's underlying member method code with example usage: obj.predict(points) and returns: numpy, list