code: def average_forward_solutions(fwds, weights=None, verbose=None):
      """Average forward solutions.
  
      Parameters
      ----------
      fwds : list of Forward
          Forward solutions to average. Each entry (dict) should be a
          forward solution.
      weights : array | None
          Weights to apply to each forward solution in averaging. If None,
          forward solutions will be equally weighted. Weights must be
          non-negative, and will be adjusted to sum to one.
      %(verbose)s
  
      Returns
      -------
      fwd : Forward
          The averaged forward solution.
      """
      # check for fwds being a list
      _validate_type(fwds, list, "fwds")
      if not len(fwds) > 0:
          raise ValueError("fwds must not be empty")
  
      # check weights
      if weights is None:
          weights = np.ones(len(fwds))
      weights = np.asanyarray(
          weights
      )  # in case it's a list, convert it
      if not np.all(weights >= 0):
          raise ValueError("weights must be non-negative")
      if not len(weights) == len(fwds):
          raise ValueError(
              "weights must be None or the same length as fwds"
          )
      w_sum = np.sum(weights)
      if not w_sum > 0:
          raise ValueError("weights cannot all be zero")
      weights /= w_sum
  
      # check our forward solutions
      for fwd in fwds:
          # check to make sure it's a forward solution
          _validate_type(fwd, dict, "each entry in fwds", "dict")
          # check to make sure the dict is actually a fwd
          check_keys = [
              "info",
              "sol_grad",
              "nchan",
              "src",
              "source_nn",
              "sol",
              "source_rr",
              "source_ori",
              "surf_ori",
              "coord_frame",
              "mri_head_t",
              "nsource",
          ]
          if not all(key in fwd for key in check_keys):
              raise KeyError(
                  "forward solution dict does not have all standard "
                  "entries, cannot compute average."
              )
  
      # check forward solution compatibility
      if any(
          fwd["sol"][k] != fwds[0]["sol"][k]
          for fwd in fwds[1:]
          for k in ["nrow", "ncol"]
      ):
          raise ValueError(
              "Forward solutions have incompatible dimensions"
          )
      if any(
          fwd[k] != fwds[0][k]
          for fwd in fwds[1:]
          for k in ["source_ori", "surf_ori", "coord_frame"]
      ):
          raise ValueError(
              "Forward solutions have incompatible orientations"
          )
  
      # actually average them (solutions and gradients)
      fwd_ave = deepcopy(fwds[0])
      fwd_ave["sol"]["data"] *= weights[0]
      fwd_ave["_orig_sol"] *= weights[0]
      for fwd, w in zip(fwds[1:], weights[1:]):
          fwd_ave["sol"]["data"] += w * fwd["sol"]["data"]
          fwd_ave["_orig_sol"] += w * fwd["_orig_sol"]
      if fwd_ave["sol_grad"] is not None:
          fwd_ave["sol_grad"]["data"] *= weights[0]
          fwd_ave["_orig_sol_grad"] *= weights[0]
          for fwd, w in zip(fwds[1:], weights[1:]):
              fwd_ave["sol_grad"]["data"] += w * fwd["sol_grad"]["data"]
              fwd_ave["_orig_sol_grad"] += w * fwd["_orig_sol_grad"]
      return fwd_ave
  
imports: import os
  import re
  import shutil
  import tempfile
  from copy import deepcopy
  from os import PathLike
  from os import path
  from pathlib import Path
  from time import time
  import numpy
  from scipy import sparse
  from .._fiff.constants import FIFF
  from .._fiff.matrix import _read_named_matrix, _transpose_named_matrix, write_named_matrix
  from .._fiff.meas_info import Info, _make_ch_names_mapping, _read_bad_channels, _read_extended_ch_info, _write_bad_channels, _write_ch_infos, write_info
  from .._fiff.open import fiff_open
  from .._fiff.pick import pick_channels, pick_channels_forward, pick_info, pick_types
  from .._fiff.tag import find_tag, read_tag
  from .._fiff.tree import dir_tree_find
  from .._fiff.write import end_block, start_and_end_file, start_block, write_coord_trans, write_id, write_int, write_string
  from ..epochs import BaseEpochs
  from ..evoked import Evoked, EvokedArray
  from ..html_templates import _get_html_template
  from ..io import BaseRaw, RawArray
  from ..label import Label
  from ..source_estimate import _BaseSourceEstimate, _BaseVectorSourceEstimate
  from ..source_space._source_space import _get_src_nn, _read_source_spaces_from_tree, _set_source_space_vertices, _src_kind_dict, _write_source_spaces_to_fid, find_source_space_hemi
  from ..surface import _normal_orth
  from ..transforms import invert_transform, transform_surface_to, write_trans
  from ..utils import _check_compensation_grade, _check_fname, _check_option, _check_stc_units, _import_h5io_funcs, _on_missing, _stamp_to_dt, _validate_type, check_fname, fill_doc, get_subjects_dir, has_mne_c, logger, repr_html, run_subprocess, verbose, warn
label_desc: Use image node_id 29 for calling a global function with example usage: average_forward_solutions(fwds, weights, verbose) and returns: fwd_ave