def modify_idx(*args, idx, dim):
    """
    Make an index that slices a specified dimension while keeping the slices
    for other dimensions the same.

    Parameters
    ----------
    *args : tuple of int or None
        constructor arguments for the slice object at target axis

    idx : tuple of slice
        tuple of slices in the original region of interest

    dim : int
        target axis

    Returns
    -------
    new_idx : tuple of slice
        New tuple of slices with dimension dim substituted by slice(*args)

        Can be used to index np.ndarray and torch.Tensor
    """
    new_idx = list(idx)
    new_idx[dim] = slice(*args)
    return tuple(new_idx)