code: def ensemble_forecasts(
      forecasts: List[QuantileForecasts],
      weighting: EnsembleWeighting = "uniform",
      ncrps: Optional[List[float]] = None,
  ) -> QuantileForecasts:
      """
      Ensembles the provided forecasts by computing a weighted average across
      quantile and time steps.
  
      Args:
          forecasts: The forecasts to ensemble. Each list item should contain the forecasts of a
              single ensemble member.
          weighting: The kind of weighting to apply for computing the weighted average.
          ncrps: The average nCRPS values of the forecasts of the individual ensemble members. Must
              be provided if `weighting` is not set to "uniform".
  
      Returns:
          The averaged forecasts.
      """
      # First, compute the weights via the provided quantile losses
      if weighting == "relative":
          losses = np.array(ncrps)
          factors = losses.max() / losses
          weights = factors / factors.sum()
          weights = weights.tolist()
      elif weighting == "softmax":
          losses = np.array(ncrps)
          ranks = losses.argsort().argsort()
          weights = sps.softmax(-ranks).tolist()
      else:
          n = len(forecasts)
          weights = [1 / n] * n
  
      # Some assertions
      ref = forecasts[0]
      assert math.isclose(
          sum(weights), 1, abs_tol=1e-7
      ), "The ensembling weights do not sum to 1."
      assert all(
          len(forecast) == len(ref) for forecast in forecasts
      ), "The different forecasts do not provide equally many values."
  
      # Then, compute the weighted average
      weighted_average = np.stack(
          [
              forecasts[i].values * weights[i]
              for i in range(len(forecasts))
          ],
          axis=0,
      ).sum(0)
  
      # And return the quantile forecast
      return QuantileForecasts(
          values=weighted_average,
          start_dates=ref.start_dates,
          item_ids=ref.item_ids,
          freq=ref.freq,
          quantiles=ref.quantiles,
      )
  
imports: import math
  from typing import List, Literal, Optional
  import numpy
  import scipy.special
  from .quantile import QuantileForecasts
label_desc: Use image node_id 1 for calling a global function with example usage: ensemble_forecasts(forecasts, weighting, ncrps) and returns: QuantileForecasts