code: def _truncate_shape(shape, rightmost_ndims_to_truncate):
      if (
          tensorshape_util.rank(shape) is None
          or rightmost_ndims_to_truncate is None
      ):
          return tf.TensorShape(None)
      if tf.is_tensor(rightmost_ndims_to_truncate):
          event_ndims = tf.get_static_value(rightmost_ndims_to_truncate)
          if event_ndims is None:
              return tf.TensorShape(None)
      return shape[
          : (
              len(shape)
              -
              # 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).
              min(rightmost_ndims_to_truncate, len(shape))
          )
      ]
  
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 6 for calling a global function with example usage: _truncate_shape(shape, rightmost_ndims_to_truncate) and returns: shape, tf, tf