code: def _discount_reward_py_2d(
      reward, sequence_length=None, discount=1.0, dtype=None
  ):
      if sequence_length is not None:
          reward = mask_sequences(reward, sequence_length, dtype=dtype)
  
      dtype = dtype or reward.dtype
  
      if discount == 1.0:
          disc_reward = np.cumsum(reward[:, ::-1], axis=1, dtype=dtype)[
              :, ::-1
          ]
      else:
          disc_reward = np.copy(reward)
          for i in range(reward.shape[1] - 2, -1, -1):
              disc_reward[:, i] += disc_reward[:, i + 1] * discount
  
      return disc_reward
  
imports: import numpy
  import tensorflow
  from texar.tf.utils.shapes import mask_sequences
label_desc: Use image node_id 4 for calling a global function with example usage: _discount_reward_py_2d(reward, sequence_length, discount, dtype) and returns: disc_reward