code: def _select_gh_by_tree_dim(gh: DataFrame, tree_idx: int):
      def select_func(s: pd.Series, idx):
          new_s = pd.Series()
          new_s["g"] = s["g"][idx]
          new_s["h"] = s["h"][idx]
          return new_s
  
      target_gh = gh.apply_row(
          lambda s: select_func(s, tree_idx), columns=["g", "h"]
      )
      return target_gh
  
imports: import numpy
  import pandas
  from typing import Optional, Union
  from fate.arch import Context
  from fate.arch.dataframe import DataFrame
  from fate.ml.ensemble.algo.secureboost.hetero._base import HeteroBoostingTree
  from fate.ml.ensemble.learner.decision_tree.hetero.guest import HeteroDecisionTreeGuest
  from fate.ml.ensemble.utils.binning import binning
  from fate.ml.ensemble.learner.decision_tree.tree_core.loss import OBJECTIVE, get_task_info, MULTI_CE, BINARY_BCE, REGRESSION_L2
  from fate.ml.ensemble.algo.secureboost.common.predict import predict_leaf_guest
  from fate.ml.utils.predict_tools import compute_predict_details, PREDICT_SCORE, BINARY, MULTI, REGRESSION
  from fate.ml.ensemble.learner.decision_tree.tree_core.decision_tree import GUEST_FEAT_ONLY, ALL_FEAT
  from fate.ml.ensemble.utils.sample import goss_sample
  import logging
label_desc: Use image node_id 3 for calling a global function with example usage: _select_gh_by_tree_dim(gh, tree_idx) and returns: target_gh, new_s