def invert(array):
    """return a dictionary mapping array values to arrays of indices
    containing those values

    """
    inverted_array = {}
    for i, val in enumerate(array):
        inverted_array.setdefault(val, []).append(i)
    return inverted_array