Shifts and pads with zero along an axis.

  Example:
    shift_and_pad([1, 2, 3, 4], 2)  --> [0, 0, 1, 2]
    shift_and_pad([1, 2, 3, 4], -2) --> [3, 4, 0, 0]

  Args:
    tensor: Tensor; to be shifted and padded.
    shift: int; number of positions to shift by.
    axis: int; along which axis to shift and pad.

  Returns:
    A Tensor with the same shape as the input tensor.

def shift_and_pad(tensor, shift, axis=0):
  """Shifts and pads with zero along an axis.

  Example:
    shift_and_pad([1, 2, 3, 4], 2)  --> [0, 0, 1, 2]
    shift_and_pad([1, 2, 3, 4], -2) --> [3, 4, 0, 0]

  Args:
    tensor: Tensor; to be shifted and padded.
    shift: int; number of positions to shift by.
    axis: int; along which axis to shift and pad.

  Returns:
    A Tensor with the same shape as the input tensor.
  """
  shape = tensor.shape
  rank = len(shape)
  assert 0 <= abs(axis) < rank

  length = int(shape[axis])
  assert 0 <= abs(shift) < length

  paddings = [(0, 0)] * rank
  begin = [0] * rank
  size = [-1] * rank

  if shift > 0:
    paddings[axis] = (shift, 0)
    size[axis] = length - shift
  elif shift < 0:
    paddings[axis] = (0, -shift)
    begin[axis] = -shift

  ret = tf.pad(tf.slice(tensor, begin, size), paddings)

  return ret