def expand_tensor(tensor, length):
    """
    :param tensor: dim: N x M
    :param length: l
    :return: tensor of (N * l) x M with every row intercalated and extended l times
    """
    rows, cols = tensor.size()
    repeated = tensor.repeat(1, length)
    return repeated.view(rows * length, cols)