def expand_as(x, y):
    """Add dimensions to x so it's dimensions are not less than y's dimensions.
    
    Dimensions are added to the end of x. If x has more dimensions than y
    from the beginning, nothing is done.

    Args:
        x (tensor): tensor to unsqueeze
        y (tensor): tensor whose dimensions are to be matched. 

    Returns: a new view of x.
    """
    num_add_dims = max(0, len(y.shape) - len(x.shape))
    x = x.reshape(x.shape + (1,) * num_add_dims)
    return x