code: def _reduce_average(
      input_tensor: tf.Tensor, axis=None, keepdims=False, weights=None
  ) -> tf.Tensor:
      """Computes the (weighted) mean of elements across dimensions of a tensor."""
      if weights is None:
          return tf.reduce_mean(
              input_tensor, axis=axis, keepdims=keepdims
          )
  
      weighted_sum = tf.reduce_sum(
          weights * input_tensor, axis=axis, keepdims=keepdims
      )
      sum_of_weights = tf.reduce_sum(
          weights, axis=axis, keepdims=keepdims
      )
      average = weighted_sum / sum_of_weights
      return average
  
file_path: addons/tensorflow_addons/metrics/r_square.py
imports: import warnings
  import numpy
  import tensorflow
  from tensorflow.keras import backend
  from tensorflow.keras.metrics import Metric
  from tensorflow.python.ops import weights_broadcast_ops
  from typeguard import typechecked
  from tensorflow_addons.utils.types import AcceptableDTypes
label_desc: Use image node_id 1 for calling a global function with example usage: _reduce_average(input_tensor, axis, keepdims, weights) and returns: average, tf