code: def trim_zeros(
      a: tf.Tensor, /, *, trim: Optional[str] = "bf"
  ) -> tf.Tensor:
      nonzero_indices = tf.where(a != 0)
      first = tf.reduce_min(nonzero_indices)
      last = tf.reduce_max(nonzero_indices) + 1
  
      trim = trim.upper()
      if "F" in trim:
          first = tf.maximum(first, 0)
      if "B" in trim:
          last = tf.minimum(last, tf.cast(tf.shape(a)[0], tf.int64))
  
      return a[first:last]
  
imports: from collections import namedtuple
  from typing import Iterable, Union, Optional, Sequence, Tuple, NamedTuple, List, Literal, Callable, Any
  from numbers import Number
  import tensorflow
  from ivy.func_wrapper import with_unsupported_dtypes
  from ..None import backend_version
  import ivy
  from ivy.functional.ivy.experimental.manipulation import _to_tf_padding
label_desc: Use image node_id 25 for calling a global function with example usage: trim_zeros() and returns: a