class_docstr: Object that performs k-means clustering and manages the centroids.
  The `Kmeans` class is essentially a wrapper around the C++ `Clustering` object.
  
  Parameters
  ----------
  d : int
     dimension of the vectors to cluster
  k : int
     number of clusters
  gpu: bool or int, optional
     False: don't use GPU
     True: use all GPUs
     number: use this many GPUs
  progressive_dim_steps:
      use a progressive dimension clustering (with that number of steps)
  
  Subsequent parameters are fields of the Clustring object. The most important are:
  
  niter: int, optional
     clustering iterations
  nredo: int, optional
     redo clustering this many times and keep best
  verbose: bool, optional
  spherical: bool, optional
     do we want normalized centroids?
  int_centroids: bool, optional
     round centroids coordinates to integer
  seed: int, optional
     seed for the random number generator
docstr: Perform k-means clustering.
  On output of the function call:
  
  - the centroids are in the centroids field of size (`k`, `d`).
  
  - the objective value at each iteration is in the array obj (size `niter`)
  
  - detailed optimization statistics are in the array iteration_stats.
  
  Parameters
  ----------
  x : array_like
      Training vectors, shape (n, d), `dtype` must be float32 and n should
      be larger than the number of clusters `k`.
  weights : array_like
      weight associated to each vector, shape `n`
  init_centroids : array_like
      initial set of centroids, shape (n, d)
  
  Returns
  -------
  final_obj: float
      final optimization objective
docstr_tok: ["Perform","k-means","clustering",".","On","output","of","the","function","call",":","-","the","centroids","are","in","the","centroids","field","of","size","(","`","k","`",",","`","d","`",")",".","-","the","objective","value","at","each","iteration","is","in","the","array","obj","(","size","`","niter","`",")","-","detailed","optimization","statistics","are","in","the","array","iteration_stats",".","Parameters","--","--","--","--","--","x",":","array_like","Training","vectors",",","shape","(","n",",","d",")",",","`","dtype","`","must","be","float32","and","n","should","be","larger","than","the","number","of","clusters","`","k","`",".","weights",":","array_like","weight","associated","to","each","vector",",","shape","`","n","`","init_centroids",":","array_like","initial","set","of","centroids",",","shape","(","n",",","d",")","Returns","--","--","--","-","final_obj",":","float","final","optimization","objective"]
code: def train(self, x, weights=None, init_centroids=None):
      """Perform k-means clustering.
      On output of the function call:
  
      - the centroids are in the centroids field of size (`k`, `d`).
  
      - the objective value at each iteration is in the array obj (size `niter`)
  
      - detailed optimization statistics are in the array iteration_stats.
  
      Parameters
      ----------
      x : array_like
          Training vectors, shape (n, d), `dtype` must be float32 and n should
          be larger than the number of clusters `k`.
      weights : array_like
          weight associated to each vector, shape `n`
      init_centroids : array_like
          initial set of centroids, shape (n, d)
  
      Returns
      -------
      final_obj: float
          final optimization objective
  
      """
      x = np.ascontiguousarray(x, dtype="float32")
      n, d = x.shape
      assert d == self.d
  
      if self.cp.__class__ == ClusteringParameters:
          # regular clustering
          clus = Clustering(d, self.k, self.cp)
          if init_centroids is not None:
              nc, d2 = init_centroids.shape
              assert d2 == d
              faiss.copy_array_to_vector(
                  init_centroids.ravel(), clus.centroids
              )
          clus.train(x, self.index, weights)
      else:
          # not supported for progressive dim
          assert weights is None
          assert init_centroids is None
          assert not self.cp.spherical
          clus = ProgressiveDimClustering(d, self.k, self.cp)
          clus.train(n, swig_ptr(x), self.fac)
  
      centroids = faiss.vector_float_to_array(clus.centroids)
  
      self.centroids = centroids.reshape(self.k, d)
      stats = clus.iteration_stats
      stats = [stats.at(i) for i in range(stats.size())]
      self.obj = np.array([st.obj for st in stats])
      # copy all the iteration_stats objects to a python array
      stat_fields = (
          "obj time time_search imbalance_factor nsplit".split()
      )
      self.iteration_stats = [
          {field: getattr(st, field) for field in stat_fields}
          for st in stats
      ]
      return self.obj[-1] if self.obj.size > 0 else 0.0
  
imports: import numpy
  from faiss.loader import *
  import faiss
  import collections.abc
label_desc: Use image node_id 4 for calling the Kmeans obj's underlying member method code with example usage: obj.train(x, weights, init_centroids) and returns: unknown