code: def _last_index(x, default_dim):
    
    if x.get_shape().ndims is not None:
      return len(x.get_shape()) - 1
    else:
      return default_dim
docs: Returns the last dimension's index or default_dim if x has no shape.