<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_numpy_bins_with_mask(bins) -> Tuple[np.ndarray, np.ndarray]: """Numpy binning edges including gaps. Parameters bins: array_like 1-D (n) or 2-D (n, 2) array of edges Returns ------- edges: np.ndarray all edges mask: np.ndarray List of indices that correspond to bins that have to be included Examples -------- (array([0., 1., 2.]), array([0, 1])) (array([0, 1, 2, 3]), array([0, 2]) """

    bins = np.asarray(bins)
    if bins.ndim == 1:
        edges = bins
        if bins.shape[0] > 1:
            mask = np.arange(bins.shape[0] - 1)
        else:
            mask = []
    elif bins.ndim == 2:
        edges = []
        mask = []
        j = 0
        if bins.shape[0] > 0:
            edges.append(bins[0, 0])
            for i in range(bins.shape[0] - 1):
                mask.append(j)
                edges.append(bins[i, 1])
                if bins[i, 1] != bins[i+1, 0]:
                    edges.append(bins[i+1, 0])
                    j += 1
                j += 1
            mask.append(j)
            edges.append(bins[-1, 1])
    else:
        raise RuntimeError("to_numpy_bins_with_mask: array with dim=1 or 2 expected")
    if not np.all(np.diff(edges) > 0):
        raise RuntimeError("to_numpy_bins_with_mask: edges array not monotone.")
    return edges, mask