def subtract_leak(cell, baseline_range, test_range, V_channel=1, I_channel=0):
    """Subtract leak conductance from the I channel of a Cell-like np.ndarray.

    Calculates leak conductance based on Rm, which is extracted from test
    pulse. Assumes test pulse is the same in each sweep.

    Arguments
    ---------
    cell: Cell-like
        [channels, time, sweeps] array.
    baseline_range: slice
        baseline time slice in timesteps
    test_range: slice
        test pulse time slice in timesteps
    V_channel: int
    I_channel: int

    Returns
    -------
    Leak-subtracted array.

    """
    Vtest_step = (
        cell[V_channel, baseline_range, :].mean(axis=0)
        - cell[V_channel, test_range, :].mean(axis=0)
    ).mean()
    Itest_step = (
        cell[I_channel, baseline_range, :].mean(axis=0)
        - cell[I_channel, test_range, :].mean(axis=0)
    ).mean()

    Rm = Vtest_step / Itest_step

    I_leak = (
        cell[V_channel, :, :] - cell[V_channel, baseline_range, :].mean()
    ) / Rm

    leak_subtracted = cell.copy()
    leak_subtracted[I_channel, :, :] -= I_leak

    return leak_subtracted