def getIndexDict(idx, labels, shape):
    """
    Get the index tuple of an index in given shape, with the labels.

    Parameters
    ----------
    idx : int
        The index that will be decomposed.
    labels : list of str
        The labels corresponding to each dimension.
    shape : tuple of int
        The shape of given object.

    Returns
    -------
    dict of (str, int)
        The index for each dimension, labelled by the corresponding labels.
    """
    res = dict([])
    for i in range(len(shape) - 1, -1, -1):
        res[labels[i]] = idx % shape[i]
        idx //= shape[i]
    return res