from itertools import product


def get_diff_slices(ndim):
    """
    Gets a list of pairs of slices to use to get all the neighbor differences for the given number
    of dimensions.
    """
    slices = (slice(1, None), slice(None, None), slice(None, -1))
    out = []
    for item in product((0, 1, 2), repeat=ndim):
        if all(x == 1 for x in item): continue
        item_inv = tuple(slices[2-x] for x in item)
        item = tuple(slices[x] for x in item)
        if (item_inv, item) not in out:
            out.append((item, item_inv))
    return out