def unflatten_like(vector, likeTensorList):
    """
    Takes a flat torch.tensor and unflattens it to a list of torch.tensors
        shaped like likeTensorList
    Arguments:
    vector (torch.tensor): flat one dimensional tensor
    likeTensorList (list or iterable): list of tensors with same number of ele-
        ments as vector
    """
    outList = []
    i = 0
    for tensor in likeTensorList:
        n = tensor.numel()
        outList.append(vector[i : i + n].view(tensor.shape))
        i += n
    return outList