class_docstr: Class to implement highly efficient vectorised look-ups.
  
  We do not utilise looping for that purpose, instead we `smartly` reshape and
  tile arrays. The trade-off is that we are potentially using way more memory
  than we would have if looping is used.
  
  Each class that inherits from this class is supposed to implement a
  particular lookup function for a certain shape.
  
  For example, look-ups for 2D table will be different in the case of 3D.
class_docstr_tok: ["Class","to","implement","highly","efficient","vectorised","look-ups",".","We","do","not","utilise","looping","for","that","purpose",",","instead","we","`","smartly","`","reshape","and","tile","arrays",".","The","trade-off","is","that","we","are","potentially","using","way","more","memory","than","we","would","have","if","looping","is","used",".","Each","class","that","inherits","from","this","class","is","supposed","to","implement","a","particular","lookup","function","for","a","certain","shape",".","For","example",",","look-ups","for","2D","table","will","be","different","in","the","case","of","3D","."]
docstr: Average the gradient based on the number of weights.
docstr_tok: ["Average","the","gradient","based","on","the","number","of","weights","."]
code: def average_centroids_gradient_by_cluster_size(
      self, cluster_centroids, cluster_sizes
  ):
      """Average the gradient based on the number of weights."""
  
      def grad(d_cluster_centroids):
          # Average the gradient based on the number of weights belonging to each
          # cluster
          d_cluster_centroids = tf.math.divide_no_nan(
              d_cluster_centroids, cluster_sizes
          )
          return d_cluster_centroids, None
  
      return cluster_centroids, grad
  
file_path: model-optimization/tensorflow_model_optimization/python/core/clustering/keras/clustering_algorithm.py
imports: import abc
  import six
  import tensorflow
  from tensorflow_model_optimization.python.core.clustering.keras.cluster_config import GradientAggregation
label_desc: Use image node_id 2 for calling the ClusteringAlgorithm obj's underlying member method code with example usage: obj.average_centroids_gradient_by_cluster_size(cluster_centroids, cluster_sizes) and returns: cluster_centroids,  grad, d_cluster_centroids,  None