def unflatten_index(i, strides):
    """Return the multiindex corresponding to the given flat index."""
    ii = []
    for s in strides:
        ii.append(i // s)
        i %= s
    return tuple(ii)
