code: def weighted_average(
      F,
      x: Tensor,
      weights: Optional[Tensor] = None,
      axis: Optional[int] = None,
      include_zeros_in_denominator=False,
  ) -> Tensor:
      """
      Computes the weighted average of a given tensor across a given axis,
      masking values associated with weight zero,
  
      meaning instead of `nan * 0 = nan` you will get `0 * 0 = 0`.
  
      Parameters
      ----------
      F
          The function space to use.
      x
          Input tensor, of which the average must be computed.
      weights
          Weights tensor, of the same shape as `x`.
      axis
          The axis along which to average `x`
      include_zeros_in_denominator
          Include zeros in the denominator. Can be useful for sparse time series
          because the loss can be dominated by few observed examples.
  
      Returns
      -------
      Tensor:
          The tensor with values averaged along the specified `axis`.
      """
      if weights is not None:
          weighted_tensor = F.where(
              condition=weights, x=x * weights, y=F.zeros_like(x)
          )
          if include_zeros_in_denominator:
              sum_weights = F.maximum(
                  1.0, F.ones_like(weights).sum(axis=axis)
              )
          else:
              sum_weights = F.maximum(1.0, weights.sum(axis=axis))
  
          return weighted_tensor.sum(axis=axis) / sum_weights
      else:
          return x.mean(axis=axis)
  
imports: import inspect
  import tempfile
  from pathlib import Path
  from typing import List, Optional, Tuple, cast, Type
  import mxnet
  from mxnet.gluon.block import _flatten
  from gluonts.core.serde import dump_json, load_json
  from gluonts.mx import Tensor
label_desc: Use image node_id 10 for calling a global function with example usage: weighted_average(F, x, weights, axis, include_zeros_in_denominator) and returns: unknown, x