def subst(x, str_re, loc):
    """
    Parameters:
    -----------
    x :  str, the string to be updated
    str_re :  str, the new string to replace
    loc : int or numpy.array, the index of where to replace x with y

    Returns:
    --------
    x_new : updated new string
    """
    if isinstance(loc, int):
        if loc == -1:
            x_new = x[:loc] + str_re
        else:
            x_new = x[:loc] + str_re + x[loc+1:]
    elif loc[-1] == -1:
        x_new = x[:loc[0]] + str_re
    else:
        x_new = x[:loc[0]] + str_re + x[loc[1]+1:]

    return x_new