code: def _sum_integral_terms(
      step_sizes: list, grads: Union[tf.Tensor, np.ndarray]
  ) -> Union[tf.Tensor, np.ndarray]:
      """
      Sums the terms in the path integral with weights `step_sizes`.
  
      Parameters
      ----------
      step_sizes
          Weights in the path integral sum.
      grads
          Gradients to sum for each feature.
  
      Returns
      -------
      Sums of the gradients along the chosen path.
  
      """
      input_str = string.ascii_lowercase[1 : len(grads.shape)]
      if isinstance(grads, tf.Tensor):
          step_sizes = tf.convert_to_tensor(step_sizes)
          einstr = "a,a{}->{}".format(input_str, input_str)
          sums = tf.einsum(einstr, step_sizes, grads).numpy()
      elif isinstance(grads, np.ndarray):
          einstr = "a,a{}->{}".format(input_str, input_str)
          sums = np.einsum(einstr, step_sizes, grads)
      else:
          raise NotImplementedError(
              "input must be a tensorflow tensor or a numpy array"
          )
      return sums
  
imports: import copy
  import logging
  import string
  import warnings
  from enum import Enum
  from typing import Callable, List, Optional, Tuple, Union, cast
  import numpy
  import tensorflow
  from alibi.api.defaults import DEFAULT_DATA_INTGRAD, DEFAULT_META_INTGRAD
  from alibi.api.interfaces import Explainer, Explanation
  from alibi.utils.approximation_methods import approximation_parameters
label_desc: Use image node_id 13 for calling a global function with example usage: _sum_integral_terms(step_sizes, grads) and returns: sums