code: def reduce_normal_eqn(
      key: Tuple, key_pattern: List[str], pdf: pd.DataFrame
  ) -> pd.DataFrame:
      """
      This function constructs lists of rows from the XtX and XtY matrices corresponding to a particular header in X but
      evaluated in different sample_blocks, and then reduces those lists by element-wise summation.  This reduction is
      repeated once for each sample_block, where the contribution of that sample_block is omitted.  There is therefore a
      one-to-one mapping of the starting lists and the reduced lists, e.g.:
  
          Input:
              List(xtx_sample_block0, xtx_sample_block1, ..., xtx_sample_blockN)
          Output:
              List(xtx_sum_excluding_sample_block0, xtx_sum_excluding_sample_block1, ..., xtx_sum_excluding_sample_blockN)
  
      Args:
          key : unique key identifying the rows emitted by a groupBy statement
          key_pattern : pattern of columns used in the groupBy statement
          pdf : starting Pandas DataFrame containing the lists of rows from XtX and XtY for block X identified by :key:
              schema (specified by the normal_eqn_struct):
               |-- header_block: string
               |-- sample_block: string
               |-- label: string
               |-- header: string
               |-- sort_key: integer
               |-- xtx: array
               |    |-- element: double
               |-- xty: array
               |    |-- element: double
  
      Returns:
          transformed Pandas DataFrame containing the aggregated leave-fold-out rows from XtX and XtY
              schema (specified by the normal_eqn_struct):
               |-- header_block: string
               |-- sample_block: string
               |-- label: string
               |-- header: string
               |-- sort_key: integer
               |-- xtx: array
               |    |-- element: double
               |-- xty: array
               |    |-- element: double
      """
      sum_xtx = pdf["xtx"].sum()
      sum_xty = pdf["xty"].sum()
  
      # Use numpy broadcast to subtract each row from the sum
      pdf["xtx"] = list(sum_xtx - np.vstack(pdf["xtx"].array))
      pdf["xty"] = list(sum_xty - np.vstack(pdf["xty"].array))
  
      return pdf
  
file_path: glow/python/glow/wgr/ridge_udfs.py
imports: from glow.wgr.model_functions import *
  from nptyping import Float
  import pandas
  from pyspark.sql.types import ArrayType, IntegerType, StructType, StructField, StringType, DoubleType
  from typeguard import typechecked
  from typing import Dict, List
label_desc: Use image node_id 2 for calling a global function with example usage: reduce_normal_eqn(key, key_pattern, pdf) and returns: pdf