code: def _assemble_r2_explained_variance(
      numerator, denominator, n_outputs, multioutput, force_finite
  ):
      """Common part used by explained variance score and :math:`R^2` score."""
  
      nonzero_denominator = denominator != 0
  
      if not force_finite:
          # Standard formula, that may lead to NaN or -Inf
          output_scores = 1 - (numerator / denominator)
      else:
          nonzero_numerator = numerator != 0
          # Default = Zero Numerator = perfect predictions. Set to 1.0
          # (note: even if denominator is zero, thus avoiding NaN scores)
          output_scores = np.ones([n_outputs])
          # Non-zero Numerator and Non-zero Denominator: use the formula
          valid_score = nonzero_denominator & nonzero_numerator
          output_scores[valid_score] = 1 - (
              numerator[valid_score] / denominator[valid_score]
          )
          # Non-zero Numerator and Zero Denominator:
          # arbitrary set to 0.0 to avoid -inf scores
          output_scores[nonzero_numerator & ~nonzero_denominator] = 0.0
  
      if isinstance(multioutput, str):
          if multioutput == "raw_values":
              # return scores individually
              return output_scores
          elif multioutput == "uniform_average":
              # Passing None as weights to np.average results is uniform mean
              avg_weights = None
          elif multioutput == "variance_weighted":
              avg_weights = denominator
              if not np.any(nonzero_denominator):
                  # All weights are zero, np.average would raise a ZeroDiv error.
                  # This only happens when all y are constant (or 1-element long)
                  # Since weights are all equal, fall back to uniform weights.
                  avg_weights = None
      else:
          avg_weights = multioutput
  
      return np.average(output_scores, weights=avg_weights)
  
imports: import warnings
  from numbers import Real
  import numpy
  from scipy.special import xlogy
  from ..exceptions import UndefinedMetricWarning
  from ..utils._param_validation import Hidden, Interval, StrOptions, validate_params
  from ..utils.stats import _weighted_percentile
  from ..utils.validation import _check_sample_weight, _num_samples, check_array, check_consistent_length, column_or_1d
label_desc: Use image node_id 10 for calling a global function with example usage: _assemble_r2_explained_variance(numerator, denominator, n_outputs, multioutput, force_finite) and returns: np, output_scores