def resize_axis(tensor, axis, new_size, fill_value=0, random_sampling=False):
    'Truncates or pads a tensor to new_size on on a given axis.\n    Truncate or extend tensor such that tensor.shape[axis] == new_size. If the\n    size increases, the padding will be performed at the end, using fill_value.\n    Args:\n      tensor: The tensor to be resized.\n      axis: An integer representing the dimension to be sliced.\n      new_size: An integer or 0d tensor representing the new value for\n        tensor.shape[axis].\n      fill_value: Value to use to fill any new entries in the tensor. Will be\n        cast to the type of tensor.\n    Returns:\n      The resized tensor.\n    '
    tensor = torch.Tensor(tensor)
    shape = list(tensor.shape)
    pad_shape = shape[:]
    pad_shape[axis] = max(0, (new_size - shape[axis]))
    start = (0 if (shape[axis] <= new_size) else np.random.randint((shape[axis] - new_size)))
    old_length = shape[axis]
    shape[axis] = min(shape[axis], new_size)
    resized = torch.cat([(torch.index_select(tensor, dim=axis, index=torch.randint(old_length, (new_size,))) if ((start > 0) and random_sampling) else torch.narrow(tensor, dim=axis, start=start, length=shape[axis])), torch.Tensor(*pad_shape).fill_(fill_value)], dim=axis)
    return resized
Truncates or pads a tensor to new_size on on a given axis.
Truncate or extend tensor such that tensor.shape[axis] == new_size. If the
size increases, the padding will be performed at the end, using fill_value.
Args:
  tensor: The tensor to be resized.
  axis: An integer representing the dimension to be sliced.
  new_size: An integer or 0d tensor representing the new value for
    tensor.shape[axis].
  fill_value: Value to use to fill any new entries in the tensor. Will be
    cast to the type of tensor.
Returns:
  The resized tensor.
def resize_axis(tensor, axis, new_size, fill_value=0, random_sampling=False):
    'Truncates or pads a tensor to new_size on on a given axis.\n    Truncate or extend tensor such that tensor.shape[axis] == new_size. If the\n    size increases, the padding will be performed at the end, using fill_value.\n    Args:\n      tensor: The tensor to be resized.\n      axis: An integer representing the dimension to be sliced.\n      new_size: An integer or 0d tensor representing the new value for\n        tensor.shape[axis].\n      fill_value: Value to use to fill any new entries in the tensor. Will be\n        cast to the type of tensor.\n    Returns:\n      The resized tensor.\n    '
    tensor = torch.Tensor(tensor)
    shape = list(tensor.shape)
    pad_shape = shape[:]
    pad_shape[axis] = max(0, (new_size - shape[axis]))
    start = (0 if (shape[axis] <= new_size) else np.random.randint((shape[axis] - new_size)))
    old_length = shape[axis]
    shape[axis] = min(shape[axis], new_size)
    resized = torch.cat([(torch.index_select(tensor, dim=axis, index=torch.randint(old_length, (new_size,))) if ((start > 0) and random_sampling) else torch.narrow(tensor, dim=axis, start=start, length=shape[axis])), torch.Tensor(*pad_shape).fill_(fill_value)], dim=axis)
    return resized