<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _set_shape_on_tensor(tensor, shape):
 """Convenience to set a shape or check it."""

  if shape is not None:
    try:
      tensor.set_shape(shape)
    except ValueError:
      raise ValueError("Requested shape does not match tensor's shape: %s vs %s"
                       % (shape, tensor.get_shape()))
  elif tensor.get_shape().ndims is None:
    raise ValueError('Unknown shape on tensor: %s' % tensor)