code: def agg_fields(tb, coef_dict=None, str_expr=None, axis="rows"):
      r"""Aggregates by linear combination fields matching either keys in `coef_dict`
      or `str_expr`. Outputs the aggregation in a :class:`.MatrixTable` or :class:`.Table`
      as a new row field "agg_annot" or a new column field "agg_cov".
  
      Parameters
      ----------
      tb : :class:`.MatrixTable` or :class:`.Table`
          :class:`.MatrixTable` or :class:`.Table` containing fields to be aggregated.
      coef_dict : :obj:`dict`, optional
          Coefficients to multiply each field. The coefficients are specified by
          `coef_dict` value, the row (or col) field name is specified by `coef_dict` key.
          If not included, coefficients are assumed to be 1.
      str_expr : :class:`str`, optional
          String expression to match against row (or col) field names.
      axis : :class:`str`
          Either 'rows' or 'cols'. If 'rows', this aggregates across row fields.
          If 'cols', this aggregates across col fields. If tb is a Table, axis = 'rows'.
  
      Returns
      -------
      :class:`.MatrixTable` or :class:`.Table`
          :class:`.MatrixTable` or :class:`.Table` containing aggregation field.
      """
      assert (
          str_expr is not None or coef_dict is not None
      ), "str_expr and coef_dict cannot both be None"
      assert (
          axis == "rows" or axis == "cols"
      ), "axis must be 'rows' or 'cols'"
      coef_dict = get_coef_dict(
          tb=tb, str_expr=str_expr, ref_coef_dict=coef_dict, axis=axis
      )
      axis_field = "annot" if axis == "rows" else "cov"
      annotate_fn = (
          (
              MatrixTable.annotate_rows
              if axis == "rows"
              else MatrixTable.annotate_cols
          )
          if isinstance(tb, MatrixTable)
          else Table.annotate
      )
      tb = annotate_fn(self=tb, **{"agg_" + axis_field: 0})
      print(
          f"Fields and associated coefficients used in {axis_field} aggregation: {coef_dict}"
      )
      for field, coef in coef_dict.items():
          tb = annotate_fn(
              self=tb,
              **{
                  "agg_"
                  + axis_field: tb["agg_" + axis_field]
                  + coef * tb[field]
              },
          )
      return tb
  
imports: import hail
  from hail.typecheck import typecheck, oneof, nullable
  from hail.expr.expressions import expr_float64, expr_int32, expr_array, expr_call
  from hail.matrixtable import MatrixTable
  from hail.table import Table
  from hail.utils.java import Env
  import numpy
  import pandas
  import scipy.stats
label_desc: Use image node_id 11 for calling a global function with example usage: agg_fields(tb, coef_dict, str_expr, axis) and returns: tb