code: def _truncate_shape_tensor(shape, rightmost_ndims_to_truncate):
      shape = ps.convert_to_shape_tensor(shape, dtype_hint=np.int32)
      rightmost_ndims_to_truncate = ps.convert_to_shape_tensor(
          rightmost_ndims_to_truncate, dtype_hint=np.int32
      )
      base_rank = ps.rank_from_shape(shape)
      return shape[
          : (
              base_rank
              -
              # Don't try to slice away more ndims than the parameter
              # actually has, if that's fewer than `event_ndims` (i.e.,
              # if it relies on broadcasting).
              ps.minimum(rightmost_ndims_to_truncate, base_rank)
          )
      ]
  
file_path: probability/tensorflow_probability/python/internal/batch_shape_lib.py
imports: import functools
  from absl import logging
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow.python.util import nest
label_desc: Use image node_id 5 for calling a global function with example usage: _truncate_shape_tensor(shape, rightmost_ndims_to_truncate) and returns: shape